color(red)("Why does HNO"_3" produce nitrogen gas instead of hydrogen gas?"
Concentrated nitric acid ("HNO"_3) is a strong oxidising agent. The hydrogen gas produced during its reaction with metal gets immediately oxidised to "H"_2"O", hence no hydrogen gas is produced. Instead, it evolves nitric oxides such as "NO"_2", NO" etc.
Take color(blue)("copper") for example,
"Cu(s) + 4HNO"_3"(aq)⟶Cu(NO"_3)_2"(aq) + 2NO"_2"(g) + 2H"_2"O(l)"
color(red)("What metals react with HNO3 to form hydrogen gas?"
"HNO"_3 (about 1% concentrated) doesn’t oxidise Mg and Mn a lot and so it reacts with them as you would expect an acid to react, releasing hydrogen.
Take color(blue)("magnesium") for example,
"Mg"+"2HNO"_3"⟶Mg(NO"_3)_2""+"H"_2"