This idiom is just a nice way to ask someone what she is thinking. When you see someone who seems to be very focused on his or her thoughts, you can say, A penny for your thoughts, and the person should tell you his or her thoughts.
A penny is a coin (money) used in the picture. Pennies are worth 1 cent. You can see pennies in the picture above.