I mean, Batman's Batsuit has his underwear on the outside, but why didn't he give Robin some pants for his costume?
Robin isn't just wearing underwear, he is wearing a leotard. Dick was part of a circus and his mum and dad were the trapeze act which he was also training in. After his mum and dad are killed in their act because of local mobster Tony Zucco taking revenge on the circus owner, Batman finds Dick. Dick convinces him to let him help and becomes Robin the Boy Wonder. His outfit consists of his leotard because of his circus background. As such he is essentially wearing clothes he is comfortable in for the role he will perform. This all happens in the first few pages of Detective Comics #38.
Of course it's worth noting that over the years there have been different Robins and different costumes. Most of the newer ones include trousers/tights in them.
The page shown above covers the origins of Robin, but not the costume or name, and the costume raised eyebrows from day one, so it was explained in a later issue. But Robin's costume, as well as his nom-de-guerre, come from a fictional (I think) organization called the Sea Robins. It was supposedly a marine-oriented boys group, like an ocean-going Boy Scouts, that Dick had belonged to. He liked the uniform so much that he designed his costume based on it.
So, it's not underwear; it's a Speedo-type swimsuit. And, as mentioned there are also tights involved.
According to the writers, it was based on Robin Hood https://en.wikipedia.org/wiki/Robin_(character)