A lighthouse and national defense are examples of public goods. The market would not provide those goods as it would be unable to charge a price to all users/consumers. It would be both unprofitable and impractical to attempt to do so. They suffer from what is known as the free rider problem.
The free-rider problem is often cited in economics as justification for taxes in order to compel most people to share the costs for public goods such as national defense or public education.
In fact, conservative economists have increasingly challenged whether the free rider problem really exists. Studies on the historical building of lighthouses reveal misconceptions about the economics of that issue, and the public expense of public schools have far outweighed their benefits.