Don't Reach Over the Fence
Never reach over a fence or through a fence to pet a dog you do not know or who is excited, nervous, fearful, or otherwise under stress.
And do not open a gate or door to enter a space with a dog without having the guardians explicit permission.
If they are in their own yard or crate or other safe space, it’s selfish of you to invade their space, and they will be the one to pay the price. Have respect for boundaries.
Many dogs will feel territorial or threatened by the experience.