There are some laws that just can't be bent. Ohms law is one of those. It dictates the law of conservation of power, which means: P_in = P_out.
So, you can't just expect the small linear regulator in a SOT23-5 case to convert 40V to 5V and 100mA without getting hot.
The power dissipated by the regulator will be: