The expectation was that FBI would lose in court. But that was not guaranteed, certainly.
FBI had multiple reasons to abandon the effort, but one was that if legal precedent was established at that time, for that case, it would be harder to bypass in future cases.
I expected the FBI to win in court because the FBI had precedent on its side. The judge had asked Apple to provide reasonable technical assistance to access data on the phone, and modifying one line of code fits well within the judge's request.