can you be refused a raise, and decide to quit and then the company hire someone to do your job at a lot more money
If I understand the question:
you asked for a raise and quit
Later you learned that they hired someone for your job and are paying them more than you
Yes, this is legal, unless you can prove discrimination.