Tens of early type galaxies have been recently reported to possess prolate rotation, i.e. significant amount of rotation around the major axis, including two cases in the Local Group. Although expected theoretically, this phenomenon is rarely observed and remains elusive. In order to explore its origin we study the population of well-resolved galaxies in the Illustris cosmological simulation. We identify 59 convincing examples of prolate rotators at the present time, more frequently among more massive galaxies, with the number varying very little with redshift. We follow their evolution back in time using the main progenitor branch galaxies of the Illustris merger trees. We find that the emergence of prolate rotation is strongly correlated with the time of the last significant merger the galaxy experienced, although other evolutionary paths leading to prolate rotation are also possible. The transition to prolate rotation most often happens around the same time as the transition to prolate shape of the stellar component. The mergers leading to prolate rotation have slightly more radial orbits, higher mass ratios, and occur at more recent times than mergers in the reference sample of twin galaxies we construct for comparison. However, they cover a wide range of initial conditions in terms of the mass ratio, merger time, radiality of the progenitor orbits, and the relative orientations of spins of the progenitors with respect to the orbital angular momenta. About half of our sample of prolate rotators were created during gas-rich mergers and the newly formed stars usually support prolate rotation.