Pajamas are loose-fitting clothing that traditionally are worn when sleeping. (And a little while before and after sleeping, too!) Wearing pajamas outside "in public" isn't common, but happens sometimes. For some nighttime activities, such as a library story hour, parents will bring small children dressed in pajamas. Usually information about the activity will say whether pajamas are expected or not.
In most K-12 schools, wearing pajamas to school isn't normally allowed. Kids might wear pajamas anyway, breaking the rules. Pajamas in class are ok at some residential schools, especially when the kids live very close to the classrooms, but typically the dress code doesn't allow this. At the college level, though, it's often accepted. But as far as we know, there aren't any colleges where most students go to class in their pajamas.
The biggest time of year for kids to wear pajamas to school, and anyplace else outside the home, is Halloween. Some schools also have another day designated for kids to dress up any way they want. This might be the last day before school lets out for the summer.
It's not very often that adults go out wearing pajamas. A Halloween party is the most frequent occasion. But there are also resorts where adults will pay lots of money to attend a pajama party!