Did Lee Harvey Oswald offer any explanation during questioning (however convoluted it might have been) for shooting the President? Was there anything left in writing that offered a motive?
I know what happened. I’m less clear on why.
Oswald denied killing Kennedy prior to his own assassination. This does not mean he didn't do it (we know many criminals deny their crimes), but it does mean that what little input we have into his thinking comes from things he did before the assassination, and those who knew him well before.
Priscilla McMillan has the unusual status of being the only person who spent significant amounts of time with both Lee Harvey Oswald (she interviewed him at length in 1959) and John F. Kennedy (she worked for him). This made her, after the assassination, take an interest in getting to know his window, Marina Oswald Porter. Priscilla is a remarkably sweet lady, still alive (age 92), and I feel honored to count her as a friend of mine (she also wrote a biography of J. Robert Oppenheimer, and we have been talking and occasionally meeting to discussion nuclear matters for well over a decade now). Her book, Marina and Lee (1977), is entirely about trying to answer why. She concludes, through Marina, that Lee was essentially quite troubled, mentally, and fairly addled in his thinking, obsessed with many political matters, including Kennedy. He was an avowed Marxist who felt Kennedy posed a dire threat to Cuba, to the Soviet Union, to the Communist world. She believes that when Lee saw that the route for JFK's caravan would carry him right past his workplace — the book depository he shot from — that it was fate telling him what to do. Here is how McMillan puts it, in the end:
He was a Marxist, and as a Marxist he was also enacting a part that had been determine ahead of time. For Marxism is a determinist philosophy, which says that the course of history is decided in advance and such choices as an individual may make have little to do with the outcome. According to Marxism, it made no difference what Lee did on November 22—history would grind on and turn out in more or less the same manner anyhow. Lee was a poor Marxist in another way as well, for Marxist philosophy repudiates the kind of terroristic act he had in mind.7 But Lee took his Marxism selectively. And according to his Marxism, history would be moved forward by his deed and the Marxist cause would be advanced. [...]
And the president came to him. Compared to the route, no other determinant mattered at all. Everything that had ever happened to Lee Oswald could have happened it exactly the way it had, his whole life could have been exactly what it had been, and it would not have made any difference. President Kennedy could have come and gone from Dallas in perfect safety. But the choice of a route that would carry the president past his window could mean only one thing to Lee—fate, duty, and historical necessity had come together in this time and place and singled him out to do the deed.
The tragedy of the president's assassination was its terrible randomness.
Now. It is very hard to get fully inside the head of even a living person (as anyone in a long-term relationship knows well), much less a dead, clearly troubled person. One must take such things with a grain of salt. One can look at the broader context — Kennedy's anti-Communism, his actions towards Cuba in particular (which made him strong enemies on the far left and the far right, both for the Bay of Pigs invasion and his unwillingness to escalate it) — but ultimately, if we take the orthodox version (Oswald acted alone) for granted, then it comes down to the mindset of a single person. And while the behavior of people acting in groups is relatively easy to predict (within margins of error), the behavior of individuals is decidedly not, even for those who know them well. Especially after they are dead. So we can take all this with a grain of salt, and say, well, we probably will never know for sure, but I find Marina's guess of his mental state (as channeled through McMillan, who is a careful and compassionate thinker — not any kind of ideologue — whose instincts I trust quite a bit) is probably as good as we're going to get from people at the time.
Most of my information comes from the warren commission report (https://www.archives.gov/research/jfk/warren-commission-report), which was conducted soon after the assassination; there has been critiques of this report but it has been mostly supported by later investigations.
A thing to remember with Oswald, and one of the most controversial aspects of the assassination, is that Oswald was himself assassinated only about 3 days after the assassination of JFK. In the brief time he was in police custody, little information could be revealed from him, due in part from his efforts and the pandemonium surrounding the investigation. Part of the reasoning towards moving Oswald was to move away from that and to protect Oswald from reprisals.
There has been a number of speculations towards why JFK was assassinated (by Oswald, or other theoretical culprits). While JFK was a popular president, he had made a number of enemies within and without the USA; part of the reason why he was driving in a open top car was to show his opponents he was not afraid, despite the warnings he had received.
The Warren Commission concludes that Oswald was not part of a conspiracy and acted interdependent, as did Jack Ruby, Oswalds killer; this has proved controversial.