I’ve learned that pants, jeans, shoes, glass are always in plural form because they consist of 2 parts. For example, jeans and pants have 2 pant legs. So why are underpants and knickers always in plural form?
Because they are all terms that derive from words that are plural for the same reason as trousers, pants, etc.1
Underpants go under your pants. Knickers get their name from the actually quite different garment knickerbockers. Shorts are short trousers/pants. Boxers are boxer shorts. Trunks were originally a sort of short breeches, with legs. And so on.
Also, most of these garments used to actually have legs, albeit not always full length. Underwear almost as brief as possible (and that's where we get briefs, which probably comes from brief underpants or something) is quite a modern thing.
1: The generally accepted reason for this is that two-legged garments weren't originally single garments, but pairs like stockings, that didn't join at the groin. I don't know how solid the evidence for that explanation is.