If $H$ is a subgroup of a group $G$ and the index (number of right cosets) of $H$ is $2$, then $a^2 \in H$ for all $a\in G$.
My attempt: if $a\in H$ then $a^2\in H$ directly. If $a\notin H$ and $a^2\notin H$ then $a(a^{-1})^{-1} = a^2 \notin H$ then $G = Ha \cup Ha^{-1}$ (the union being disjoint). But $e\notin Ha$ because $e=a^{-1}a$ and $a^{-1}\notin H$. Also $e\notin Ha^{-1}$ because $e = aa^{-1}$ and $a\notin H$. Then we have a contradiction. So $a^2$ must be in $H$ in both cases.
I think it's ok but I dont feel the arguments with the identity $e$ are right and don't see how to justify them more rigorously.
Thanks in advance
Your proof looks fine, just a bit complicated. Here is another way. If $a\in H$ then we are done. If $a\notin H$ then $Ha\ne H$. Since there are only $2$ right cosets we conclude that $H$ and $Ha$ are all the right cosets, and $a^2$ must be in one of them. But if we assume that $a^2\in Ha$ then there is an element $h\in H$ such that $a^2=ha$. We multiply by $a^{-1}$ from the right side and get $a=h\in H$ which is a contradiction. So $a^2\in H$.