How does Finder decide whether a file extension needs to be hidden? I'm using Mavericks and I noticed some of my files have their extensions hidden and others don't. How does Finder decide whether a file extension needs to be hidden?

I know I can prevent this inconsistency by selecting the "Show all filenames extensions" option in Finder Preferences.
Finder doesn't decide this - it is a flag saved with the file. The app saving the file sets or clears this flag. You can do a Get Info on a file to toggle this setting on a per file basis.