This is often used when people ask a question that is a bit 'random', without much reason behind asking the question other than purely to satisfy their curiosity.
Ex: Just out of curiosity, if you could only eat one type of food for the rest of your life, what would you choose?
Other situations people might use it is to sound more friendly, but I would personally advise against it, as it can be interpreted in different ways. For example, if you say:
"Just out of curiosity, what's your favorite food?" to a girl as a guy, they might think that you are interested in them, rather than if you had just asked "What's your favorite food?"
Hope that helps a bit!