My horse had the same problem. My vet prescribed injections of estrone (a female hormone which helps to strengthen the ligament in the stifle joint.)Treatment usually consists of 2 injections in the muscle twice weekly for 4 consecutive weeks, then as needed therafter.
Also important is exercise. Alot of times the stifles become weak from lack of exercise. I make sure that my gelding is always gets sufficient exercise. It’s recommended that you do alot of work up and down hills. Consistent walk/trot work especially up and down hills, will build back up the muscles that support the stifles. Works well in geldings and stallions, not so much in mares.
Some other therapies include:
-The infusion of counterirritant within and around the medial and middle patellar ligaments will cause scarring and shortening of these ligaments which will make it extremely difficult for the patella of the stifle to lock in the upward position.
-Resection of the medial patellar ligament is a surgery that will prevent the stifle from locking.
Always consult your veterinarian.