How do managers know if a person is a good or a bad programmer?
I will start with a gross sweeping generalization: most managers cannot tell a "good" programmer from a "bad" programmer.
With that out of the way, what most managers (I've met or worked for) consider "good" in a programmer is not the same set of skills that another programmer would consider "good."
how do they do it?
A results-oriented manager is going to look for things like "smart" and "gets things done." They aren't going to care if you show up to work in sweatpants as long as you get the stuff done on time and on budget.
A process-oriented manager is more concerned with "how things get done." This means getting to work on time, wearing the right clothing and do you have the right cover sheet on the TPS report.
person works well, if he or she should be put in charge of something
Being "in charge" takes different skills than writing code. If a person has the people-skills needed to lead a team, then that person should get tapped to do so. If you promote people based on the key job elements of the job they are currently performing, eventually they get to a level where they're now incompetent. This is called The Peter Principle.