Assuming the candidate doesn't drop out on her or his own:
The delegates have complete control over the convention. They could vote in a rule prior to the nomination vote that said that the candidate was not eligible and vote in someone else. Many of them may still be bound to vote for that candidate, but the rules would say that the candidate could not win. There is no rule saying explicitly that having enough bound delegates to make up a majority of the delegates awards victory.
For example, if Hillary Clinton is convicted of abuse of classified information after winning 2383 bound delegates in primaries, her own delegates could vote in a rule precluding anyone convicted of a felony from winning the nomination. They'd be bound to vote for her on the first ballot but that wouldn't count. Most would be unbound on later ballots and could vote for someone else. That someone else might be Bernie Sanders but not necessarily. They could pick someone else entirely.
To continue, Clinton could then turn state's evidence against Donald Trump on a bribery charge. Trump gets convicted too but has at least 1237 bound delegates. The Republican delegates modify rule 40 to exclude votes for convicted felons. Some of the delegates may be unbound immediately, e.g. Minnesota and Oklahoma are only bound if the candidate is nominated. Cruz, Kasich, or some other candidate could be nominated.
Note: neither scenario is likely. This is just a semi-realistic chain of events to illustrate what could happen.
All that said, if either party did this, they'd need a really good reason to avoid a backlash. They'd probably try hard to get a unanimous decision on the rule change so as to provide cover against charges of interfering with the election. They'd specifically try to recruit the previous supporters of the candidate to be removed.