Why is gym called pe?

PE stands for Physical Education. "Gym" (short for gymnasium) is simply a widely-accepted nickname for a physical education course, that most likely arose because most PE courses are held in the school's gymnasium.

In many schools, "Gym" has become less about education of physical fitness, and more of a time to wear kids out between classes (a sort of recess with required physical activity).