Well yes, of course it's legal. There's nothing criminal about selling in-game pixels for real money.
But it IS against SE's ToS, and if you are caught buying or selling gil for real money, you risk having your account permanently banned. SE doesn't have to have chat evidence. They can look at gil transfer logs, and if they see a large sum of gil being transferred from a known gil seller, they ban those accounts very often.