You should definitely have a home inspection. The purpose is to make you aware of any defects that may exist before you settle on your new home. If your contract is contingent on a home inspection and you find defects, the following options are available to you:
the seller will remedy all of the items noted
the seller will extend you a monetary closing cost
credit in lieu of the repairs
the seller will choose not to remedy any defect, in
which case you can void your contract, or you can
proceed having full knowledge of the home's condition
Use the home inspection to inform you of possible defects only. Cosmetic issues are not a consideration at this time. These things you can change at your leisure to suit your tastes. Major items of concern are:
Foundation, roof, and overall structural integrity
Electrical & mechanical operation
Discuss these major items with your inspector to help you determine how you should proceed with your contract.
This is conducted prior to closing. The purpose is to make sure that the home is in substantially the same condition as when the contract was written, and to make sure that all agreed home inspection items have been corrected.
At closing, ownership is transferred, monies are collected, and keys may be delivered. The settlement agent will ensure that all of the terms of the contract have been met. Also, the agent will review your loan documents with you. Any walk-thru issues will be remedied by the seller, or negotiated.