''What's in your mind?'' means ''What are you thinking?'' ''What's on your mind''? mean ''What's worrying you?'' for example, ''I've got so much on my mind right now''
In your mind is deeper, more philosophical, fundamental ("in"). [Don't make too fixed a rule of this though.] On your mind is more surface - troubles, events etc ("on").
Compare how salt is easier to remove when it's on your food, and much harder when it's in your food.
The main thing to remember is that as children, words like "in" "at" "on" "from" etc are all learnt as physical words. As the child grows and becomes more philosophical, these words, although used for more abstract concepts such as time or mind, still carry the same "feeling" that they had as physical words, and their abstracter uses reflect this, even when you can't consciously define