Yes, you definitely need to get it before settlement. In the state of PA, there is a contingency property insurance clause that you can choose to exercise within the time frame (10 to 15 days after execution day or depends on how you choose those time frame) to obtain home owner insurance. You should get a quote from an insurance company and see whether you like the price that you pay or not. Sometimes if the property is not insurable due to existing insurance claims or pending litigation from the current owner or previous owners to the insurance company, the insurance company that you are choosing may not want to insure the property you are purchasing. At this time, you can notify the seller in writing that you don't want to or can't buy this house because you can't obtain home owner insurance for it. If you don't exercise this clause prudently within allotted time frame, you might be on the hook for it. Sometimes, if the property is in the flood zone, you need to be aware that you may have to buy flood insurance, quite expensive, in addition to the home owner insurance. Knowing what you may have to pay out, you can save yourself whole lot troubles.
I am not sure where you are in this process, but if I were you, I will get a quote from the insurance company asap and don't pay them in advance, just tell the insurance agent you will pay at time of settlement.
Best of luck to you.