Do I need to apply for ESTA if I have a stop-over in the United States?

Even if your final destination is not the United States and you’re stopping over through for just an hour or two, you will still need to get an ESTA authorisation. You may not even be able to board your flight if you do not have a valid ESTA, as your airline will request this before your departure. This is to make sure that Border Security will know exactly who is able to enter the U.S. at what particular period of time. This is because are no transit areas in the U.S., and you are in American territory from the moment you land.
Don’t forget that while your ESTA can be approved in mere minutes, it’s always best to apply at least 72 hours before your travel date, or just after buying tickets, even if it is just for a quick transit or even if you will be remaining in the aircraft for the entire layover.
If your application is refused, there are a couple of solutions to try and resolve this. The first thing you can do is to wait for 10 days and apply to obtain ESTA authorisation again, in case there were any issues with the form when you first submitted it. There is an option on the ESTA application to indicate that your visit is just a transit, so when you fill out the application again you can select that option.
If your application for ESTA is still unsuccessful, then you will need to obtain a C-level visa, which is specifically for transit, in order to complete your journey. The most common of these is the C-1 visa, which is used for transits when travelling for personal reasons, and each travelling person, including children and infants, would require their own visa. With such a visa, an immigration officer at the port of entry can admit you for a period they decide, which can be no longer than 29 days.