Because he opposed communism.
Remember that the MOB also lost a multi million dollar cash cow in Cuba. The CIA had a lucrative war (drugs) going in Vietnam. And...the Deep State was alive and well even then. Presidents were "hired" to do their bidding or suffer the consequences.
JEK was assassinated because J. Edgar Hoover did not want JFK and his brother RFK to go after the mob. Hoover feared the mob would try to blackmail him with their knowledge of his transsexual activities. When Hoover tried to blackmail JFK because of his flings with women, it backfired. RFK was prepared to fire Hoover when the assassination plot was hatched. Also, Hoover hated the Kennedys because of Kennedy patriarch, Joseph Patrick Kennedy Sr’s ties to the mob. Bottom line, it was Hoover who conspired with power hungry LBJ to launch the assassination.
This battle between Hoover and the President have significance today with Comey.