Apple recommends using its Mac laptops when the ambient temperature is between 50 and 95 degrees Fahrenheit, or 10 to 35 degrees Celsius. That's a wider range than most people will encounter indoors, but the upper limit is easy to approach on a hot summer day. Apple also specifically warns against leaving a MacBook in a parked car, where temperatures can climb beyond its recommended range.
The important word in Apple's guidance is ambient. The 95-degree limit refers to the air around the laptop, not how hot its aluminum enclosure might become while sitting in direct sunlight. Apple doesn't publish a separate direct-sunlight limit for MacBooks, so it makes sense to move into the shade rather than treating a temperature below 95 degrees as an all-clear for using one in full sun.
There's a longer-term reason to avoid excessive heat, too. Ambient temperatures above 95 degrees Fahrenheit can permanently reduce battery capacity, meaning the battery may not last as long on a charge afterward. Charging a device in high temperatures can cause additional damage.
Heat also matters differently depending on the MacBook you have. All Apple Silicon MacBook Air models use passive cooling rather than a fan, dissipating heat through the chassis. MacBook Pro models use active cooling for sustained, demanding workloads. Either way, giving the laptop shade and room around it to shed heat is preferable to making its cooling system work against direct sun.