how is the bay of pigs invasion illegal?

Invading other sovereign countries is frowned upon, by and large. I know the Geneva Convention as well as I know Cuban history, but I'm pretty sure it doesn't go down well.