Here ‘bargain’ does not refer to something bought cheaply, but to an agreement made between two parties. When one party realizes too late that the agreement is more to the other party’s advantages than his own, he is said to have made a bad bargain; but as the agreement is binding on both parties, he has no alternative to make the best of it, to accept the fact that he has lost on the deal.
In a figurative sense, to make the best of a bad bargain is to try to be cheerful in the face of an unhappy situation and do your best with it.