The proper moment to shout "Objection!" is when an attorney disagrees with a statement being made by the opposing attorney or prosecutor.
In a courtroom, it is a formal way of challenging testimony or a line of questioning that a lawyer believes is improper. Popularised by games like the Ace Attorney series, the dramatic shout has become an iconic part of legal drama, even if real objections tend to be far more understated.