Because an anonymous transition has higher priority than deferred events. In the second example, the transition from State2 to State3 is an anonymous transition. 'Anonymous transition' means transition without event.
When the current state is State2, there are two outgoing transitions. One is the anonymous transition, the other is to State5 transition that have Event1 as a trigger. Then, the anonymous transition is chosen. Deferred event is not consumed. After transitioning to State3, deferred event is fired. So the transition from State3 to State4 is occurred. That why, State5::on_entry() is not displayed.