I have a question regarding details of piston engine power ratings. Why were WW2 era engines limited in time for war emergency maximum power? If they were rated for that maximum power why limit them at maximum power for like 5 minutes?

Is it related to the engine cooling and aftercooling systems not being able to reject the heat at those power ratings except for a short amount of time?

Yes, the ability withstand the stresses and reject the heat of WEP ratings is why they were limited to the the placarded times. There was also a limited amount of alcohol-water ADI fluid for engines so equipped, so once that was consumed, WEP could not be "safely" maintained.