When a company should raise capital depends on a few factors, with the result being that a company should raise capital when it would provide the most upside for the company's existing stockholders.
A company should raise capital if it is running out of money to operate the business. Because raising money can take a few months--and nearly always takes at least one month--many founders find it prudent to begin fundraising if they find their runway is shorter than about six months.
Another factor to consider in determining when to raise capital is how close you are to a significant decrease in the risk to investors of investing in your company. If your company has a shippable product, it is a less risky venture than a company that is an idea and a dream. If your company has a customer, has overcome a regulatory hurdle, or has recurring revenues/users it is less risky still. The less risky your company is as an investment, the higher a valuation you will be able to raise money at, and the less diluted the existing stockholders will be from a capital raise.
One more thing to consider in timing your capital raise is how much time you as a founder have to commit to raising capital. Meeting investors, pitching your company, negotiating the terms and facilitating the diligence process can take up the majority of a founders time for weeks to months. You should only raise money when raising money is a better use of your time than the other zillions of things that are also on your plate.