Baggage security screenings happen at or near the airport, usually right after check-in. When you drop your bag at the counter or self-drop, it typically goes straight into the baggage handling system (BHS). Along the conveyor belt, it passes through heavy-duty scanners – these may be X-ray or 3D-CT machines specifically for hold bags. Some airports have large centralized screening rooms where bags queue for scanning before sorting into flight batches.
If you use off-airport check-in, the bag will be transported under seal to the airport and screened there before being allowed on a flight. In cases of connecting flights, any bag that missed a standardized screening (for example, on a very short connection or if coming from a non-screening partner airport) may be re-screened at the transfer point to meet security rules (iata.org).
In short, screening happens as early as possible in the process: usually immediately after acceptance. It might happen inside the terminal, or even en route to the plane. The important thing is, by the time the bag is loaded, an official record shows it has been examined.