It varies by state. In California, you can get a ticket if the light is red when you enter the intersection. In Oregon, you can get a ticket if the light is red when you exit the intersection.
Then what are you supposed to do if the light turns red while you're still on the intersection? Linger on the intersection until it turns green again?
I realise the purpose of the lights is to keep the intersection clear for the flow of traffic that has the green light, but in real life traffic situations, things rarely work out that way and some common sense is always needed.
Obviously my wording was poor. If the light turns while you are still in the intersection, you've earned a ticket.
In both states, you are supposed to not enter the intersection unless you have both time and space to make it through. In Oregon, intersections tend to stay clear more, because people generally follow that rule more. In California, if the light is yellow and traffic is stopped on the other side, many people will enter anyway, knowing they can't go through, just to claim their "turn". And totally block traffic when the light changes. Not so much in Oregon.