The query you are using is not a Self join. Your query is also returning the same result as expected but that will return all categories and display name if exists in the detail table.
I have added another category:
INSERT INTO #category(categoryc,categoryx) VALUES (101,102)
Result:
categoryc categoryx
bmw mercedees
feat toyota
mazda suzoky
NULL NULL
If you are looking for eaxct match then use the folowing query:
SELECT CDC.categoryname AS categoryc, CDX.categoryname AS categoryx
FROM #category c
INNER JOIN #categorydetails CDC ON c.categoryc = CDC.categoryid
INNER JOIN #categorydetails CDX ON c.categoryx = CDX.categoryid
Result:
categoryc categoryx
bmw mercedees
feat toyota
mazda suzoky