2 AnswersNew Answer
It is done when you want to use your own class on something but do not want the user to use it directly or when it does make sense to put it in, I only used it once in C# with unity in a space invaders game. The inner class was a Missile class with informations about missiles (GameObject (a class of unity), speed and direction) I made it in the game class. I do not know if it was the right thing to do but I did not need this class elsewhere
Inner classes are a good way to subdivide complex tasks. If you find yourself with an overly complicated object, an inner class can help clarify the code. Even if the division of labor is still too situationally specific, the encapsulation the subprocess is still a good design practice. It keeps your object divisions cleaner, and lets you focus on a single level of abstraction at a time. If you end up being that inner class functionality elsewhere, it's easily transferred!