I know that free a neutron breaks into a proton because a proton has less mass and energy. Then, why do protons not break into quarks, since they have even less energy?
Or why do gluons join quarks?
When you say quarks "have even less energy," I assume you mean less mass-energy. While quarks individually have less mass-energy than a proton, three separated quarks have more energy than a proton. The quarks attract and bond to each other to reach a low energy state, and breaking that bond requires an energy input - which, ironically, supplies the necessary energy for a new set of quarks to form. So if you try to split a particle into a quark-antiquark pair by supplying energy, you just end up with two particles instead.