When I stretch my hamstrings, I get an acute pain right behind my knee, what exactly is that pain? Is it ligaments? Is it my gastrocnemius?
Pain in the back of the knee (‘popliteal’ region) does have some common causes. The most common being a popliteal cyst caused by the buildup of synovial fluid in the knee that migrates to the back of the knee. The underlying cause is usually related to arthritis, or, acute cartilage injury to the knee.
A popliteal cyst, also known as a Baker’s cyst, is a fluid-filled swelling that causes a lump at the back of the knee, leading to tightness and restricted movement. The cyst can be painful when you bend or extend your knee.
If it is a Baker’s cyst, then, stretching the hamstrings may cause some painful discomfort in the popliteus muscle.
It could be the inner and outer head of the gastrocnemius, but if you're doing the stretch where you lean forward into a stretched out leg, then that pain is perfectly normal. In my experience, it feels more like semimembranosus.
But yeah, I experience the same thing, so I do another hamstring stretch, which doesn't require full extension of the leg.
I still do the leaning forward one too, specifically to work on the pain in the back of the knee.
I'll assume it's tendons, as I can't imagine that you're loading up your ligaments with a standard hamstring stretch, but I guess it's possible. Either way, there's a lot of connective tissue in there and no relevant muscle so the distinction between ligament and tendon might not be of much material relevance.
The anterior knee pain you're experiencing is bad though, to be sure. To solve the problem, try bending your knee slightly.
A much superior stretch you may want to try is a standing forward bend, aka uttanasana. Check out the reference below (higher res here), and note the beginner stance on the right where the person is using two blocks. Hand position is important, and I've always been advised to try to push my butt into the corner between the ceiling and the wall behind me, if that makes sense. Keep your butt up and push it up and back. Take your shoes off, keep your feet pretty close together, and spread the weight evenly from your toes to heels. A slight bend in your knees is completely acceptable.