The end zones were invented as a result of the creation of the forward pass.
In the earliest days of the forward pass, the pass had to be caught in-bounds and could not be thrown across the goal line (as the receiver would be out of bounds).