This is one with a simple and straightforward answer: the best time to consult with a lawyer before you sell your house is before you sign a listing contract, a sales agreement, and talk with a potential buyer or realtor.
If you sign a listing contract with a realtor, you will be signing certain rights away, including whether you have the right to sell the property yourself without having to pay a commission; also, if you talk with a potential buyer about contractual terms, there may be a number of relevant legal things of which you are unaware, which should also be discussed.
The best time for you to talk to the lawyer is before you do any of these things, and by doing so, you can discuss and evaluate various rights and obligations that you will have. Also, if a realtor presents a proposed listing contract to you, it is generally advisable to have your lawyer review it before you sign it. All too often, people go forward with these sorts of transactions, signing the contracts, and then take them to their lawyers to review them after things are signed. Ordinarily, that is too late to make modifications!