There are two types of failure - muscular failure, and mechanical failure.
Muscular failure is when the neuromuscular system can no longer produce adequate force for a muscle / muscle groups to contract concentrically. For example, during bench press when you bring the bar down to your chest, and your chest, triceps and shoulders can’t generate enough force to push it back up.
Mechanical failure is when you can no longer perform the movement by executing safe and correct form through a full range of motion. For example, if you perform a set of 10 squats and for the first 7 your legs reach parallel. However, for the last 3 reps you are unable to achieve your previous depth, your knees start to cave in, and your back begins to arch. Technically you lifted the weight for 10 reps, however you were unable to execute each one with proper form.
The current consensus is that you need to be within ~2-5 reps of muscular failure to provide an adequate stimulus for muscle growth. This implies that you don’t need to take every set of every exercise to the absolute limits – in fact research suggests it may be beneficial to keep a few reps left in the tank.
Imagine going to failure on your first set of squats and maxing out at 10RM – this is likely to impair your following sets, perhaps resulting in only 7 reps for set two, and 5 reps for set three, resulting in 22 reps total. Now, imagine if you left one rep left in the tank for that first set – you may have been able to match performance on your following two sets, resulting in 27 total reps. That’s five extra reps – and let’s say you were squatting 140kg, that’s an extra 700kg volume load. That’s a hell of a lot of stimulus you may have missed out on due to accumulating fatigue on your first set.
Now does that mean you should never aim to hit failure? Not necessarily. There may be an appropriate time and place to hit muscular failure, for example during 1RM testing, AMRAP testing, or during the last set of your isolation exercises. However, to protect yourself and avoid accumulating injuries, it’s recommended that you aim to avoid mechanical failure, while muscular failure is fine under certain circumstances.