It is widely considered very poor etiquette to give advice in the gym to a person you do not know and who has not asked you for it. This includes advice on form, no matter how dangerous you believe it may be to them. Even if you have a genuine desire to help, it is much more likely that you will be seen as rude, condescending, or arrogant by the person if you have approached them unasked and without a prior relationship to make giving advice appropriate.
In addition, you don’t know anything about the person’s background, goals, or training program, and even if it appears they’re doing something wrong, there may be a good reason for it being different from what you expect to see. They may have a physical limitation or simply be doing something you’ve never seen before, but which is perfectly valid. The correct course of action is always to mind your own workout and go about your business.
The one possible exception to this is if the other person is putting other people at risk for injury. However, this is something that you should notify the gym staff about, as they have the proper authority to handle the situation appropriately and attempts by you to do so will likely just start an argument.