Birds can safely sit on power lines without being shocked because the bird is not touching both the hot and ground or hot and neutral wires at the same time.
For electricity to shock a bird or a person or other animal you have to be touching both wires or be touching the hot wire and the ground as well to be shocked.
There's not a path to the ground for the bird to get shocked when they're perched on top of the electrical wire so that's why they can safely sit on the wire.