One idea is that he felt let down by JFK when he heard stories of assassination attempts on Castro. There are reports that Oswald has said about killing Eisenhower due to him being a lead capitalist who was exploiting the poor of the US. He admired Castro, and did, it seems, admire Kennedy, but may have turned against him when heard stories of attempts by the US to kill Castro. When he found that the motorcade was passing his place of work this seemed like his chance.
A West German geologist, Volkmar Schmidt, was working in the US when he met Oswald in 1963 and discussed politics with him. He said Oswald was "obsessed with anger towards Kennedy" because of Kennedy's policies towards Cuba. He said Oswald was angry over the Bay of Pigs in particular.
Oswald regularly read radical left publications - the Daily Worker and Militant - which reportedly were filled with stories critical of American policy towards Cuba.
So, why would an admitted Marxist like Oswald, an ardent admirer of Castro's who tried to defect to Cuba, "like" an anti-communist, anti-Castro figure like JFK? It doesn't make sense to me.
And for a guy who "liked" JFK Oswald sure seemed to have a complete lack of interest in what happened to Kennedy that day. He leaves the building right after the shooting not inquiring about what happened, he never talks to anyone about what happened, and he's not interested in finding out on radio or TV what happened at all. That's odd behavior for a political person like Oswald who supposedly "liked" the president.
Here is Schmidt's account from the PBS special "Who was Lee Harvey Oswald?"
"Lee Harvey Oswald brought up in the conversation with me the fact that he really felt very angry about the support which the Kennedy administration gave to the Bay of Pigs invasion. It turned out that Lee Harvey Oswald really idealized socialism of Cuba, while he was critical of the socialism in the Soviet Union. And he was just obsessed with his anger towards Kennedy."
And yes, we also have Marina's statement the he "liked" JFK and that they cried together when the Kennedys lost their infant son. And De Mohrenschildt said that Oswald "admired" JFK over his civil rights policies. So one can take either side on this.
Source:
https://www.pbs.org/wgbh/pages/frontline/shows/oswald/etc/script.html