The first energy level can be occupied by a maximum of 2 electrons.
Each hydrogen atom has only one electron which occupies the first energy level.
Therefore, two hydrogen atoms will each share this one electron and form a covalent bond. By doing this (sharing electron), each of the two atoms will now be having 2 electrons (its original electron + the shared one from the other atom) and are now both stable forming a hydrogen molecule.