Why can a hydrogen atom become either an ion or a part of a molecule?
It can either donate its single electron or share it.
If it shares, e.g. with another
It may also donate its electron. It then becomes a naked proton, that can attach to e.g. water, to form the acid hydronium ion