Stan Lee answered this question in an interview with Eric Spitznagel of Vanity Fair (March, 2011). You can read the transcript on ComicBookMovie.com.
VF: If it weren’t for the Comics Code, would the Hulk’s pants have ripped off like his shirt?
Stan Lee: I guess it probably would have. So occasionally the Code did some good things.
VF: Did you ever try to make sense of the Hulk’s magical purple pants? Why did they always conveniently remain intact while the rest of his clothes were ripped to shreds?
Stan Lee: I just figured that Bruce Banner had probably been a friend of Reed Richards [Mr. Fantastic from the Fantastic Four], and Reed had given him some elastic trousers. There’s an explanation for everything, but you may not be technically advanced enough to follow me on all of this.
"Power Man & Iron Fist" #65 circa 1980 offered an insight into this question. Luke Cage, notorious for losing his yellow shirts due to violence and mayhem, visits his local haberdasher for replacements...
In the later part of the TV series, his jeans ripped up to the top of his thighs, which is fair enough, considering lou ferrigno as the hulk had the dimensions of a bodybuilder with small waist and huge muscles elsewhere, and ferrigno was considerably smaller than his comicbook counterpart.
In the comic however, (especially the Sal buscema era) those darn purple pants of his are not like normal jeans or trousers at all. They are more like super durable and stretchy long legged purple underwear worn under jeans or trousers, that rips at the ends. I reckon that would make more sense, considering they always hugged his legs as the hulk and as banner after his transformations. In the comic, they never looked like everyday jeans or trousers. Perhaps that's what Reed Richards or Tony Stark made for his friend Bruce Banner?
As I remember in looking at the early (Kirby) issues of the Hulk comic, Dr. Banner wasn't a "total square." He wore purple pants with cuffs. Not daring, as he was otherwise dressed like a good researcher of the day would have. Blues, grays, browns and greens, were also common colors for pants. But dark purple slacks were not unseen. They could have been something like pleated work slacks from Sears. Those slacks had hip pleats. I know that when you snap off the belting fabric you still only gain about two to four inches at the hips and no inseam. And as the joke goes, "If my pants were that tight, I'd turn green too."
OK, so we give Bruce pleated work slacks with Inseam Guard (1966?) and almost no wear. Brand new! That might let the fabric stretch out to paper thin for a while. Is the tension itself holding the stitching in place? Is the fly fused shut?
In the Incredible Hulk series episode called ''Prometheus'' Lou's Hulk did indeed lose his trousers. In part one he transformed by those rocks, and as the helicopters approached the Hulk actually tore his trousers off, revealing shorts underneath.