Is there a name for an idiom that intentionally reverses key words for dramatic effect?

I think the term you are looking for is antimetabole.

"In rhetoric, antimetabole (/æntɪməˈtæbəliː/ AN-ti-mə-TAB-ə-lee) is the repetition of words in successive clauses, but in transposed order; for example, "I know what I like, and I like what I know"." https://en.wikipedia.org/wiki/Antimetabole

Honestly I always thought it was chiasmus - but apparently it is not.

"In rhetoric, chiasmus or, less commonly, chiasm (Latin term from Greek χίασμα, "crossing", from the Greek χιάζω, chiázō, "to shape like the letter Χ") is a "reversal of grammatical structures in successive phrases or clauses – but no repetition of words"...."

https://en.wikipedia.org/wiki/Chiasmus

I'm pretty sure the JFK line is used as a standard example of chiasmus, but the correct term is antimetabole.