What is it called when you are asked a question that has nothing to do with the subject at hand and is sometimes meant to make you look bad?
I think it is a legal term used in a court setting.
English Language & Usage Stack Exchange is a question and answer site for linguists, etymologists, and serious English language enthusiasts. It only takes a minute to sign up.Sign up to join this community
I think you're looking for a loaded question.
Have you stopped beating your wife?
is a loaded question and is designed to make the answerer look bad. Whether they say "Yes, I've stopped beating my wife" or "No, I haven't stopped beating my wife," the answerer is assumed to have, at one point, beaten their wife on a regular basis.
In a legal setting you might mean: Leading the witness or a leading question.
It has a legal definition (from US Legal):
Leading the witness is the method of questioning a witness by which s/he is directed to answer them in the way expected by the attorney. The query suggests to the witness how it is to be answered or puts words into the mouth of the witness. In such questioning the answers will be apparent in the questions itself. Leading questions should not be used on the direct examination of a witness unless necessary to develop the person's testimony. Leading questions are proper in cross-examination or allowed if a witness is declared by the judge to be a hostile or adverse witness.
This is a phrase used in courtrooms and so strongly fits with that requirement. A leading question is intended to get an answer that is in the questioners favour, hence it may make the answerer or someone else attached to the case "look bad". In a courtroom setting, there won't be questions completely out of context, but a leading question may be unexpected.
You may be thinking of the term
A question posed by a reporter in an effort to trick a politician into looking stupid or saying something damaging.
In Texas, we call a loaded question a Trick Bag. The unwitting victim is asked a question like "Are you still a member of the communist party?" This is the Trick Bag. Any answer you give is "jumping into the Trick Bag".
Consider the question Dick Durbin asked Judge Brett Kavanaugh during his confirmation hearing for a seat on the U.S. Supreme Court:
Would you welcome an FBI investigation into the sexual assault allegations?
No matter how Kavanaugh answers the question, the answer can be used against him.
You might try, “trick question” or “hostile questioning.” Hostile is more about the tone or intent; a trick question is more about cleverly posing a question with no good answer.
Other words for unpleasant, relentless questioning are badgering, haranguing, berating or hectoring—although those all connote rudeness and anger, while a trick question is more often outwardly polite.
Tommy Tran’s suggestion, “loaded question,” and Pam’s suggestion, “leading question,” are both good. “Leading question” is more likely to be used in a courtroom, but it also has a more specific meaning as legal jargon than in everyday speech. If I complain, “That’s a loaded question,” I’m accusing the other person of trying to imply something he or she is not willing to say directly. If I complain, “That’s a leading question,” I’m accusing the other person of trying to make me say what he or she wants, or put words in my mouth. Neither refer only to trying to make the person being questioned look bad; a lawyer coaching me to sound good or stick to my story might be told to stop “leading the witness,” or a question might be “loaded” with the implication that someone else is bad or wonderful.
Another related legal term is “complex question,” although unlike the previous two, this isn’t a term in common use. It means that a question presupposes something false. The classic example is, “Have you stopped beating your wife?” (Especially in a context where a witness is only allowed to answer “Yes” or “No.”) This has an even more obscure Latin name.
The word “abuse,” as in “abusive question” or “abusing the witness,” is the closest piece of legal jargon but has become obsolete; the word means something more violent today.
Another related legal term is “perjury trap,” where a prosecutor or investigator asks a suspect about some wrongdoing and you’re in trouble no matter what you say. If you confess, you’re guilty. If you deny it and they think you’re lying, they can indict you for that. If you refuse to answer on the grounds that it may incriminate you, that makes you look suspicious.
As a literary example, you might look at Mark 12:13. A few traditionalists familiar with the King James Version might recognize the obsolete turn of phrase, “to catch him in his words,” but modern translations say something like, “to trap him in a statement” or “to trap him by what he said.” This meant very politely asking for a yes-or-no answer to a question that sounded reasonable on its face, but where any straight answer would get you in trouble with somebody.
Mathematics has “coffin” or “killer” (in the past, when they were used to keep Jewish students out, sometimes called “Jewish”) questions:
The Mathematics Department of Moscow State University, the most prestigious mathematics school in Russia, had at that time been actively trying to keep Jewish students (and other "undesirables") from enrolling in the department. One of the methods they used for doing this was to give the unwanted students a different set of problems on their oral exam. These problems were carefully designed to have elementary solutions (so that the Department could avoid scandals) that were nearly impossible to find. Any student who failed to answer could be easily rejected, so this system was an effective method of controlling admissions. These kinds of math problems were informally referred to as "coffins". "Coffins" is the literal translation from Russian; in English these problems are sometimes called "killer" problems.
a misrepresentation intended to harm another's reputation
seems close, but does not really fit that it has nothing to do with the subject at hand
Detraction also comes to mind
a lessening of reputation or esteem especially by envious, malicious, or petty criticism
The difference between the two is that calumny is a false statement but detraction is a true statement, just one that is not generally known.
Directly relevant is the logical fallacy of "begging the question", or Latin petitio principii, or original Greek attributed to Aristotle, "τὸ ἐξ ἀρχῆς". This may not imply a specific intent to make the addressee look bad, but that is often an intent or outcome of such fallacious questioning or reasoning. I don't have information about use of the term in courts per se, but in academia, especially in the subjects of logic and philosophy, its use is common.