In the standard model, particles are described as excited states of a (quantum) field. A simplified picture of a field would be wiggly sheet of rubber. We can distinguish between two kinds of fields:
(Massless) This is a sheet of rubber that is so free to wiggle that no matter how lightly you touch it you will set off a vibrational motion.
(Massive) This is a sheet of rubber that is not so free to wiggle, and in fact if you poke it with a strength below some threshold (i.e. the mass gap) it will not wiggle at all.
Therefore gluons and photons are massless because they can be formed with arbitrarily low amounts of energy (i.e. you get a wiggle no matter how softly you push).
It's not true that every particle must have mass, all a particle needs in order to interact with matter is to carry energy/momentum.