Always worth remembering that the vast majority of troops on both sides in the Civil War were state volunteer units, not regulars.

That said, mustaches used to be quite the thing (especially with cavalry units). Beards were common in the field, but not so much in garrison. As for reasons...try pest control for one. Back in the day lice were a major problem, and keeping hair short (to include facial hair) was one of the main control options available. I suspect that over time it just became a "symbol of good order."