The role of magnetic reconnection and differential rotation in spheromak formation