How does SpaceX test it? Have they needed to solve this problem?
By having a much higher launch cadence and then analyzing the flight hardware afterwards.
Also, they don't have anything human rated going beyond LEO. Coming back from the moon means you're going significantly faster and thus need a better heat shield
Crew Dragon flew an automated demo flight before flying with crew. It was proceeded by 20 flights of Dragon 1 over 10 years.
Starship's heatshield has already been tested full-up half a dozen times. Many changes have been made as a result.
They do iterative flight testing. Starship is I believe on its twelfth flight test; the first one was in 2023.
SpaceX tests these in prod. Kinda like Artemis I did.
By blowing up unmanned spacecraft and letting the ones that survive catch fire?
SpaceX has a reusable launch vehicle, so they could afford to fly a whole mess of unmanned flights before they stuck a human in there
There were 19 successful unmanned Dragon 1 missions before Crew Dragon, and an unmanned Crew Dragon mission before the first crewed one (actually two missions, but one didn't reenter from orbit). The heat shield material and design was essentially the same and so there was a great deal of flight heritage.