Moisture, heat, and agitation is what shrinks wool. Untreated wool fibers little tiny rough scales and to felt you have to have those fibers rub against each other and hook onto each other, leading to a matted mess of fibers. Essentially shrinking wool is like when your dog or cat gets fur mats between their legs.
I would expect most wool underwear is made from treated, or superwash, merino. That won't shrink (much) because the fibers don't have those rough scales. They're smooth. (That being said, there are degrees. Some woolens aren't well treated and they will shrink anyway.)
If the washing instructions allow for ANY machine washing, it's made from superwash wool. Non-superwash wool would shrink (felt) if it even looked sideways at a washing machine. Just like that nice expensive wool sweater we got for Christmas and wore only once…until it's washed.