Plain version: you can only insure something whose loss would actually hurt you financially. Without that rule, insurance would become a bet on someone else's misfortune.
The rule (§§280, 287): if the insured has no insurable interest, the contract is void. Policy wording cannot fix this. Under §287, a stipulation that the insurer will pay whether or not the insured has an interest in the property is itself void. A man who buys a fire policy on his neighbor's house, with no stake in it, holds a void contract.
Who has an insurable interest (§§281, 283): an interest in property, or a relation or liability connected to it, is insurable if a contemplated peril might directly damnify the insured. The owner qualifies, and so does a bank holding a mortgage, because a fire could directly harm its security for the loan. A mere expectant interest not founded on an actual right or a valid contract is not insurable, such as a son who only hopes to inherit, a neighbor who would lose a nice view, or a frequent guest.
How much, and when (§§284, 285, 286):
Amount: measured by the extent the insured might be damnified by the loss. A 40% owner of a $500,000 building has an interest of about $200,000. A carrier or depositary is the exception: its interest extends to the value of the thing it holds (§285).
Timing: for property, the interest must exist both when the insurance takes effect and when the loss occurs. It need not exist in between. The rule that an interest is needed only at the start belongs to life and health insurance, not property.
Indemnity: a payment should restore the insured to about the same financial position as before the loss, with no profit. A $18,000 covered loss under a $100,000 limit (no deductible) pays $18,000. The limit is a cap, not the amount owed, and paying more would reward people for having losses.