Kingsguard members serve till the death. But during the events of the books and TV series, some members were expelled. What was the first precedent when somebody was expelled from Kingsguard? For example, if a Knight became completely crippled, or maybe fled to the far East.
If we are talking about dismissal as in honorable retirement package, Barristan Selmy would be the first. He was the first one to have been dismissed on account of inability to protect the King due to advanced age (Or in reality to give Sandor a place on the Kingsguard).
While there is no precedent for dismissing a kingsguard knight on physical incapacity, there are cases in which a KG was considered dismissed after he fled or after he broke his Sworn vows. Deserting and breaking your vows virtually amount to the same thing. Quoting Ser Georld "White Bull" Hightower, Lord Cmdr. of KG:
“Ser Willem Darry is fled to Dragonstone, with your queen and Prince Viserys. I thought you might have sailed with him.”
“Ser Willem is a good man and true,” said Ser Oswell.
“But not of the Kingsguard,” Ser Gerold pointed out. “The Kingsguard does not flee.”
Before/After him, following sworn brothers were dismissed on following accounts:
Lucamore Strong aka Lucamore the Lusty. Dismissed on charge of breaking his vow of celibacy and sent to wall after being gelded by Jaehaerys the Conciliator . His dismissal is implied by him being sent to the wall, because according to Vows of Kingsguard:
During his time as a member of the Kingsguard, a member is not allowed to hold lands, sire children, marry, or have any worldly allegiance except to his monarch.
and according to vows of Nights Watch:
I pledge my life and honor to the Night's Watch, for this night and all the nights to come.
So it is clear that you can't be a member of the Kingsguard and Night's Watch at the same time because that would be conflicting with Vows of both the orders. It is also proven because in the aftermath of Robert's Rebellion, Ned Stark urged Robert Baratheon to send Ser Jaime Lannister to the wall so that he could no longer serve in position of a Kingsguard. Robert however did not heed to his advice and Jaime continued to serve as a KG. If Robert had listened to Eddard Stark, that would have ended Jaime's commision as a KG and opened a vacant post in the KG.
Boros Blount dismissed on charge of Cowardice after surrendering Prince Tommen to Tyrion's men. Later reinstated by Lord Tywin.
Sandor Clegane aka the Hound. Dismissed after his desertion during battle of Blackwater Bay and later declared an outlaw. It is implied because after he left, Lord Tywin gave his place to Boros Blount in aftermath of the battle. This handles case of your sub-question about what happens if a KG deserts his duty and flees?
According to the book, Barristan Selmy is the very first. His dismissal is what sets precedent for any future discussions or incidents along those lines.
In fact, crippled doesn't seem to be a factor, as Jaime seems sure that he will find precedent to stay in the Kingsguard. As seen in Jaime's second chapter in A Storm of Swords part 2 (his return to King's Landing):
"It was poison that killed Joffrey, not sorcery." Lord Tywin glanced at Jaime's stump again. "You cannot serve in the Kingsguard without a sword hand-"
"I can," he interrupted. "And I will. There's precedent. I'll look in the White Book and find it, if you like. Crippled or whole, a knight of the Kingsguard serves for life."
"Cersei ended that when she replaced Ser Barristan on grounds of age. A suitable gift to the Faith will persuade the High Septon to release you from your vows. Your sister was foolish to dismiss Selmy, admittedly, but now that she has opened the gates-"
"- someone needs to close them again." Jaime stood .....