I talked about the development of Japanese castles here, which you can go read.
The castles you are thinking of are the large and elaborate ones from the late-Sengoku and Edo period. The main reason Japanese castles are built with retaining walls rather than freestanding curtain walls is because of geography and climate and the resulting construction techniques. The first castles (and probably the vast majority of castles, which don't survive) were simple wooden structures on top of hills or mountains. This is simply because it's the easiest, least labour/resource-intensive way to build the most defensible structure. The mountain is, well, a mountain, and scaling the slopes is hard. The mountain itself is the main defense. After making a simple castle enclosure, the main human addition therefore is to make the approach harder. This mean cutting the slopes steeper, cutting ditches and moats into the hills (similar thing), and cutting down the trees so attackers can't hind behind them. The earth can then be used to make level plateaus to build on, which you use trees you just fell for.
However, Japan is rainy (according to World Bank in 2017 Japan had 1,668mm of rain compared to rainy UK's 1,220mm), battered by typhoon (over 20 a year), and also arguably the most earthquake-prone country on earth (look at Japan covered in red compared to blank UK, France, and Germany). An earthen hill cut steeper than is natural, clear-cut of trees, and having to support the extra weight of man-made structures on it is going to be prone to landslides. The solution, then as now, is to encase the hill, in this case with rocks. And that is what more powerful (rich) lords started to do to their more permanent castles. The hill, now able to support more weight, can also now hold the huge keeps of Japanese castles. This is likely why large stones superstructures on top of mountains were not built, at least not before making the retaining walls first. With the retaining walls and the wooden superstructure on top that lined them (don't forget), scaling is basically virtually impossible already, so there's no point building tall curtain walls on top.
Because this was the traditional construction method/style/culture, when castles became more frequently built on hills in the middle of a plain rather on mountain tops and ridges, the construction method was kept. Castles built on flatter areas like Ueda, Fukui, Tsuruga, Nijō, and Nagoya, if we ignore the giant keep itself, not surprisingly often they have "more" freestanding walls combining digging deeper with a raised rampart rather than a complete plateau.
Also note that many European mountain castles, like Stirling, Hohenzollern, Krak Des Chevaliers, do use the retaining-wall style, and even relatively flat Caephilly have significant sections that use retaining wall. So obviously the necessities and advantages of the style, especially when it needs to/can be used in conjunction with geography, was well known in Europe as well.
Just to follow up with the excellent answer by r/ParallelPain above, I'd like to point out there are plenty of examples of Japanese castles incorporating various types of "freestanding walls" in their Nawabari / 縄張 or design form.
The first example come to my mind would be Akita Castle / 秋田城. It is a excellent example of Heian era Hirajiro / 平城 type of castle design, somewhat resemble contemporaneous Chinese city enclosures. [1] The entire Akita Castle complex was built on a gentle hill rising no more than 40 meters above surrounding fields, and both gaikaku (外郭 / outer walls) and naikaku (内郭 / internal walls) of the castle enclosed of "freestanding" dobei (土塀) type of walls walls. See here for a restored section of the Akita Castle outer wall, and here for a model of one Akita Castle's naikaku walled complexes.
If you're thinking more along the lines of "freestanding" stone castle walls, they are frequently found in koguchi 虎口 ("tiger's mouth," or fortified entrance) part of the Japanese castle, especially in those more extravagant Edo era ones. See here for an example of koguchi stone walls at the Kumamoto Castle. In fact if you take a look at the overall nawabari of Edo era Kumamoto Castle, you will find many different types of wall structures, freestanding or otherwise, used in its overall design. The Hiroshima Castle from the similar era is also known for its walled koguchi structures, and in this case a unique type of moated koguchi design known as umadashi goguchi as shown here and its nawabari drawing shown here at the middle. [2]
[1]西ヶ谷恭弘編著『城郭の見方・調べ方ハンドブック』東京出版 2008年
[2] 八巻孝夫 「馬出を考える:その概念とことばの由来」 『中世城郭研究』 中世城郭研究会〈第3号〉、1989年、32-49頁。