The United Kingdom General Elections use a First Past the Post district-based system, where one candidate wins in each district. Some districts are safe seats for particular parties. For example, the Wokingham parliamentary constituency has always been won by the Conservative Party, with margins varying from 13% in 1966 to 43% in 2015. With such figures, what is the incentive for the Labour Party, Liberal-Democrat Party, etc., to field candidates at all?
Votes in lost circumscriptions count toward the headline percentage of the popular vote you will hear about after the general election and also increase the amount of funding the party will be able to claim from the state (in the UK and elsewhere there is some state funding for political parties based in part on the number of votes gained in the last election, see e.g. Short Money) so that's two practical reasons to have candidates in as many constituencies as possible.
Beyond that, having candidates for almost every seat is also part of what makes a party one of the main parties in the country, there are many others who only contest a few constituencies and a few who strives to be present in most places (UKIP had 539 candidates, the BNP and the Green Party a bit over 300 each, for 573 constituencies in total).
Thus, in a slightly different context, the French Front National made a point of fielding candidates in each and every district. That's a way for them to increase their showing in the parliamentary elections and to show they are not some fringe group hoping to stage a protest or become the junior partner in a governing coalition but a real contender to lead the country.
It does not cost much either, you mostly need to find some activists who don't have a political career and don't mind being publicly associated with your party and the defeat that is sure to come. In some cases, it could be young politicians who hope to impress and get a winnable seat next time around. In others, like the Front National, they do not campaign at all and the party leadership mostly hope they will shut up and avoid saying something stupid that could embarrass them in the national media.
(Incidentally, in the UK, even the main parties do not contest every constituency in each election. The speaker of the House of Commons traditionally leaves his party and runs unopposed, at least by Labour, the Liberal-Democrats and the Conservatives, other parties like UKIP, the Green Party or the SNP do contest the seat.)
The very informative answer given by "Relaxed" covers all the main points, but is a little off the mark in one small respect, which I'd like to expand on.
When it comes to finding candidates to contest unwinnable seats a party does not usually have to seek out party members who are committed enough to stand yet don't mind forgoing a political career by publicly losing; it also has available a far wider pool of candidates who do want a political career and are willing to prove it by publicly losing. Contesting an unwinnable seat is the traditional first step on the ladder to become an MP. It allows an aspiring MP the chance to demonstrate commitment to the party and develop his or her campaigning skills. It also allows the party high-ups to see how well the would-be MP performs on the doorstep and on the hustings. If a candidate manages to increase the party's eventual share of the vote by more than that party's national trend in the general election, or decrease it by less, then he or she will probably be offered a winnable seat next time, and the party will be glad to have found a potential rising star.
An additional point is that the British electoral system is not completely ossified. In the 2015 General Election many seats that had been Labour for decades fell to the Scottish National Party. If the SNP had not fielded candidates in those seats when they looked hopeless it would not have been in a position to win them later.