How do you know when you play in free stroke or rest stroke on your sheet music? If it is not indicated, what effect does it have on the music? Is it indicated most of the times?
The type of stroke is usually not indicated. It's up the the guitarist to choose the most appropriate stroke. Faster or lighter passages are probably better played tirando (with a free stroke), and strong or slower melodies usually sound better apoyando (with a rest stroke). But there is no general rule. Try to master both and try both to choose which one comes closer to your desired interpretation. If possible, also listen to (and watch!) accomplished players play the piece you're working on.
There are several considerations in order to "correctly" determine which type of stroke to use.
If you look at guitar methods of the late 19th and early 20th century you will find that there are a lot of indications for the use of the apoyando or rest stroke technique. From what I've read that was the trend during that period of time and a good example of it are the Sagreras books in which, not only will you find the indication in every single study but also if you read the text that accompanies them, most of the time it says something like "be very careful in using a rest stroke on the notes that make up the melody".
That last part brings me to another consideration. When you use the rest stroke, the note will sound stronger, louder, more defined so it makes sense to use it for the melody of the piece since its the part that you want it to be clearer. Think of it like the guitar is a band and the melody is the lead singer, you want to clearly hear the singer and the rest of the members of the band are accompanying him, it's the same with the guitar, the melody should be heard clearly and the rest of the notes are the accompaniment.
That being said, and like I mentioned at the beginning, this technique became trendy in the late 19th century, which means if you are playing anything from the Renaissance or Baroque and want to stay "true to the style" you should use very few rest strokes if at all.
Of course these would be the basic "rules" about the use of both types of strokes but if you scour the internet you will find players using rest strokes when playing Bach or Scarlatti while others never use them when playing Granados or Torroba.
In the end you need to be able to comfortably use both since they are part of your technique arsenal, and use them when they make sense, whether for stylistic or personal choice reasons.