How was Duke senior freed from the perils of the court in As You Like It?
Duke Senior was freed from the perils in court by the strange conversion of Duke Frederick to a religious monastic life. Since romance in all its many variations is one of the thematic concerns of As You Like It, Duke Frederick's conversion must be seen as a religious variation on the theme alluding to the monastic belief in wedding oneself to God for a lifetime of faithful service.
Duke Frederick was enraged to find out that all his plans were sabotaged. Rosalind had escaped form him by departing under cover of night for Arden forest. His daughter Celia forsook him and left with Rosalind, choosing sincerity and friendship over her father's authority. Orlando had escaped Oliver. All were converged in Arden forest, the abode of his old enemy and the man from whom he had stolen the throne, Duke Senior.
Duke Frederick organized an attack to conquer and capture all of them, especially Duke Senior, for whom more and more nobles were deserting Frederick. At the edge of the forest, Frederick got into conversation with an old religious hermit who miraculously led Duke Frederick to a change of heart, because of which he forgave everyone and returned the dukedom to Duke Senior and retired into a monastic life of seclusion and peace. Therefore, there were no longer any court perils for Duke Senior--or anyone else--to face.