You probably do not have sufficient free travel between pedal and master cylinder If the piston does not return fully to its stop, fluid can't escape back to the reservoir if it expands due to heating, so pressure is trapped.
Next time it happens, try loosening the two master cylinder bolts and pulling it up slightly. If that releases the pressure, you have located the problem. It may be that there is a problem with the pedal box or the stop light switch is adjusted too far, preventing the pedal from returning fully, or thepedal return spring may be damaged in some way. Pibly even problems with the push in teh pedal, or the pivot shaft.
If it is an accumulation of tolerances that is causing the problem, master cylinder shims are available from Somerford.