The ceremonial hammer is called a gavel and usually looks like this:
Stock image used with permission
(Gavels in India and in the U.S. Senate which received its gavel as a diplomatic gift from India, don't have handles.)
It is used in both courts and public meetings (most often city council meetings or legislative body committee meetings, but also, for example, in both the U.S. Senate and U.S. House) for the functional purpose of getting people's attention and telling them to shut up without having to make a shrill whistle or having to yell, both of which would be less dignified.
It is a very ancient tradition in the common law tradition that dates all of the way back to when English lords presided over disputes between their subjects personally, before the specialized position of judge was invented, and has been used for pretty much the entire history of the United States, even dating back to the colonial period. I don't know if gavels are used outside of the common law legal tradition or not.
It tends to be used more in public meetings than courtrooms these days because court hearings are not nearly as well attended as they used to be, so there aren't enough people making noise in the courtroom to make its use necessary. I have used one a few times to preside over political party meetings when I was political party official.
These days, a typical court hearing today has only a judge, a bailiff, another court clerk, one or two lawyers for both sides, one or two parties for each side, and up to about four witnesses or spectators, plus a jury and a court reporter in a typical jury trial.
Also, in court almost everyone is well behaved because the judge has direct contempt of court power (another vestige of directly imposition of justice by a lord or king that dates to the same time period as the gavel) and can throw anyone in the room in jail summarily if desired for minor misbehavior, a power that other people presiding over public meetings usually lack.
But, historically (pre-television for the most part), in contrast, watching court hearings was a major form of community ritual and/or entertainment and crowds of dozens or more spectators were common.
Sometimes in a court, when it is used, it is wielded by the bailiff (a court official charged with maintaining order in the court and supervising the jury) who often doubles as a law clerk or administrative assistant to the judge, rather than the judge. The bailiff is also the person who calls out "all rise" when the judge enters the room at the beginning of a hearing and when the judge leaves at the conclusion of a hearing. In rural areas, the bailiff/law clerk is usually armed. In urban areas, the sheriff for the county typically provides court security and the bailiff only ceremonially maintains courtroom order.