There is a way using no air flow with Rjc thermal resistance to estimate active junction temperature.
You must know Pd, Tamb and Rjc to compute Tj or for THT parts if given Rjc, Rca... for j = junction, c= case and a= ambient....and T= temp. SMT parts depend on substrate greatly.
But comparing mounted and uncounted parts could derive these values for Rca using similar small sized parts like 220’C/W in small transistors. (Not tried)
Tj= (Tc-Tamb)*Rca/Rjc+Tamb.. (? Verify?).
Often Only Rja is given due to many differences in substrate material and area so guidelines are given.
Due to latency of thermal mass in power devices you must also know the Safe Operating Area or compute the junction thermal pulse response if an OEM like Rohm provides the RC time constants for each layer of material.
Another active method is to use a pulsed off current to measure the threshold voltage of a PN junction which has a known thermometer characteristic at 1mA. e.g. ~600 mV @ 25’C @ 1mA for Vbe then apply the NTC slope to estimate Tj.
Calibration in boiling water will serve to verify assumptions of a discrete part.
In general the lead temp may be closer to Tj than the epoxy insulated body. This is especially true for Cathodes on epoxy LED’s where the cup-holder is attached while the anode is bonded with a whisker gold wire that is a poor heat conductor and fuses easily yet is almost invisible.
Yet ultimately, if your case temp is too hot to touch > 65’C at room temp, you may have a Tj reliability problem at 40’C ambient. Arrhenius Law states for every 10’C rise the MTBF reduces 50%. There may be exceptions for some materials that this applies every 12’C rise above ambient.