Usually what you describe is a symptom of a worn timing chain or belt. Though the timing is slightly off due to the wear, it will still function when cold. Once the engine gets hot all the other parts involved (pulleys and gears, valve stems, lifters and push rods etc.) expand and throw the timing so far off, the engine will no longer run, until that is, it cools down and the other parts contract once again.