Sheep often are prone to wander from the herd and leave the shepherd's care. Some more than others, and some as soon as they have the chance. In the case of the latter, shepherds would sometimes break the legs of the sheep, if that's what it took, to prevent their rebellion. The end result was not only that they wouldn't wander off, but because they couldn't walk, they would get a lot of time being directly carried in the shepherd's arms. This solved not only the immediate concerns of them walking into danger, but the bond from the one-on-one time they wouldn't of had otherwise made them more inclined to cling to the shepherd thereafter.
Sometimes the hardest things we go through are for our good (Rom. 8:28). We may not understand it nor like it anymore than I imagine a sheep likes having it's legs broke, but when we look back from eternity I'm convinced we'll be as glad about God's discipline here and now for what it accomplished for there and then (1 Thess. 5:23, Gen. 50:20). Jacob understands (Gen. 32:25) so does the Corinthian man living in sin (1 Cor. 5:5). You don't need to understand the why, but don't lose sight of the Who, the Good Shepherd, who would rather lay down His own life than lose you (John 10:11).