I'm not a doctor and I put some of my personal empirical information at the end. Get an MRI by an Orthopedic surgeon. Follow his advice.
The cushion between the vertebrae might be damaged causing the bone to hit the nerves coming out of the spine. In my younger days I powerlifted and I would "throw" my back out every once in awhile. It would take 7 to 10 days for the nerves to quiet down. I haven't had a lower back injury in decades and I'm in my 60's. Disclaimer I've had some minor irritation once in awhile but nothing like I use to in my youth. This worked for me and it might not work for you. It might make it worse. Consult a doctor. I made my lower back nearly bullet proof by including these three exercises. Semi stiff deadlifts off a block getting a good stretch. Second is weighted back extensions using a horizontal back extension bench and not the new 45 degree ones where the resistance dies off near the top. Lastly hanging leg raises. I speculate that hanging leg raises decompress the spine.
You're probably young and can do stuff like heavy squats and deads. Some younger guys and especially older guys have to watch spinal compression that could lead to nerve problems. I see guys doing these barbell shrugs with a crazy amount of weight bouncing doing short range of motion. No doubt that in time many will regret doing that to their spine. So much safer to do a full range of controlled rep cadence with a lighter weight so you're not crunching the spine with momentum with a heavy weight.
I see guys deadlifting with a big fast jerk to start the weight. Yes, you can lift more doing that but it's not safe. Will everyone have problems? No, but it's a risk. The momentum increases the weight load on the spine drastically. Apply pressure to getting that barbell off the floor until enough is there to get it moving. You want to make yourself stronger and not delusionally lift a heavier weight by jerking it off the ground.
The barbell squat is something that causes problems for many eventually. The compression while bending over with a barbell squat can cause problems over time. It can also be bad for the hip. Clarence Bass, Big Lou, Grimek and host of other champs have had their hips replaced. They might state the squat has nothing to do with it but I wonder? A safer alternative is the dumbbell squat for older trainers. Hear me out. Someone will say I do my squats with 300lbs. My gym doesn't have 150lbs dumbbells. That's the beauty of the dumbbell squats. A lighter weight is harder than the equivalent weight of a barbell. What do I mean? If you are using 300lbs for a barbell squat set, two 90lbs dumbbells might be too much weight to use. You have to do it correctly though. The technique is to use straps and hold the dumbbells at your sides. Squat as upright as you can concentrating on sinking your butt. If you barely bend your legs and deadlift the weight you're doing it wrong. It's a brutal exercise. Completely bend your legs.
Another contributor to a bad back is the leg press. Guys use so much weight barely bending their legs that sometimes their butt moves curling in the seat from the weight again crunching the spine. Lighten the load and concentrate on bending the legs. Lower the back board so your legs can come back.
Lastly with all the hamstring work we do in the gym many times we lose flexibility. That sets the chain of issues into action causing the lower back to be strained. This can be corrected by gently stretching the lower back while exercising the bicep femoris with semi stiff deadlifts and stretching exercises.
I'm sure what I wrote will send google experts into motion and two week personal training people to their computer folders to quote "impressive" terms and a recommendation of unconventional exercises.