Roofing filter is the first IF filter in the IF chain, right after the first mixer.
Roofing refers to the idea that it prevents the rest of the IF chain (very high gain) from getting saturated or distorted. That means, everything ahead of the roofing filter must have ana much much wide dynamic range (and consequently lower gain) than what follows the roofing filter.
The concept and beefy implementation of the roofing filter were to improve the receiver performance in bands crowded with strong stations, such as 40m when broadcast stations existed in the middle of 7.0xx MHz range and more commonly during contests and DXpeditions. In receivers of 20th-century designs, when a strong S9+ station appeared just a few kilohertz off your QSO partner at S2 or S5, you may no longer copy easily or at all. Receivers in 2010 or later designs and used in some of the performance transceivers (such as Elecraft K3, KX3 or Kenwood TS590) are much better, in part due to roofing filters.
Even in DSP rigs, many use IF DSP architecture, where the RF signal is downconverted to a low frequency (a few hundred kHz or lower, sometimes even 0Hz) and then sampled. In that case, the roofing filter may even be an active filter using OPamps (such is the case with KX3 roofing filter module).
In direct sample DSP architecture, the notion of roofing filter no longer applies. The dynamic range (bits) of the A/D converter and the preselector are the key elements determining the immunity from strong signals at nearby frequencies just outside the receiver bandwidth.
In particular, noise blankers and AGC are nonlinear devices in the IF chain, and NB operates on a wideband signal (wider bandwidth than the one required for communication signal) and it is very susceptible to interference from strong signals at nearby frequencies. When AGC malfunctions due to strong nearby signals, the target signal can be suppressed entirely or reverse-modulated by the interfering signal. With sophisticated roofing filter and overall refinement in the receiver architecture, these problems became much alleviated in the post-2010 performance equipment.
Sidenote: leave NB off when you don't need it, especially in older rigs, for better experience.
Roofing filter's bandwidth is usually wider than the communication bandwidth. The ultimate IF bandwidth (such as 2.7kHz for SSB or 50 to 500 Hz for CW) is determined by a narrower filter later in the IF chain. A common misconception among amateurs (e.g., the Facebook KX3 group) is that people often argue that they installed an optional roofing filter, but it did not help reduce QRM. Of course!