By all measures, this election was the CPC's to lose. They had control over the government and its messaging, they had a financial warchest rumoured to be many times the size of their competitors, and they had control over the timing.
So, what did they do wrong? Lots.
Harper had spent his entire time as leader of the CPC consolidating his control over the party and its top ranks. It had become the Stephen Harper Party, for better or worse. Personal brand of the leader is often a powerful force in making a party's success. Making the party all about the leader is never a good idea. Leaders sooner or later lose their legitimacy, or they become tired of what they are doing and lose their "touch". Although the CPC appeared unified behind Harper, that doesn't mean Canada was unified behind them.
The first thing that Harper did was run a campaign that was about fear and division. He lashed out at Liberal leader Justin Trudeau, snidely calling him "Justin" at every turn, claiming that he had neither the smarts nor the experience to be the next Prime Minister. He played the classic socialist bogeyman arguments against the NDP. All this is pretty normal fare in Canadian politics, but somehow Harper took it to new lows - borrowing tactics from US Republican / Teaparty politics.
When attacking his peers didn't get him the traction he wanted, Harper turned on his own campaign manager, Jenni Byrne and brought in Australian Lynton Crosby. Shortly after Crosby's name was floated, we got two gems out of Harper - "Old Stock Canadians" and the Niqab issue. Both were distinctly vile to Canadian sentiments. While they briefly got traction, they both backfired on Harper. Yes, a somewhat ham-handed response by Mulcair destroyed his support in Quebec, that support didn't come Harper's way to any great extent even in Quebec. Canadians saw this for what it was - KKK style racism, and they turned on Harper in droves.
Then, when Crosby jumped ship to save his "professional reputation" (as a purveyor of division and racism, I might add), Harper turned back to his usual stock approaches to campaigning, hoping desperately that Canadians wouldn't put together what his government was doing.
Harper ran a most un-Canadian campaign. He threw people under his political bus. His candidates weren't to be found campaigning on the ground in most ridings, even his cabinet ministers were nearly invisible most of the time. That made the campaign all about him, and Canadians don't _like_ Harper. They might have voted for him previously, but really that was because the Conservative attack machine had managed to assassinate their characters before the election - in essence, making Harper the least unpalatable option.
It didn't do the CPC any favours that in the last four years they had accrued the baggage of repeated scandal (Mike Duffy, Pamela Wallin, Patrick Brazeau, Bruce Carson and others), a reputation for not answering questions in the House and a legislative agenda that more and more Canadians rightly saw as mean-spirited, if not downright malicious (Bill C-51, Bill C-24, the "Fair Elections Act"). No amount of sweater vests and kittens can overcome the shadow that casts.
So, what does the CPC need to do to rebuild? A lot, and very little of the post-election analysis out of CPC members has even broached the realities. MPs need to recognize that they are intelligent, thinking beings who should speak out for their constituents, not just act as party brass dictate they should. A decade of "Harper's Trained Seal Act" has left the party with a deficit of ideas and original thought in the senior ranks.
Further, the party has to acknowledge that it has acted in an incredibly racist manner. Yes, Jason Kenney (Minister of Curry in a Hurry) built up a lot of support within Canada's various immigrant communities, but he did so while part of an organization which gained much of its backing by playing off mistrust between groups, rather than unifying them. The niqab issue, like the turbans in the RCMP 20 years earlier, is incredibly divisive and destructive. It was a "throw an entire vote under the bus" moment, and the government's continued appeals even after losing the case in the courts merely cemented the overt racism of Harper's campaign. The CPC cannot be seen to govern for all Canadians until it acknowledges that.
Further, legislation like Bill C-24 and the "Barbaric Cultural Practices" act are vile. C-24 created a two tier citizenship. Anyone who holds, or is eligible for, citizenship in another country is suddenly subject to further punishment, not at the discretion of the courts, but at the decision of the minister - making it a political decision. I'm still not sure how many Canadians really understand how vile that really is. The "Barbaric Cultural Practices" act was another part of the Conservative war machine. It was designed specifically to attack the most visible crimes associated with the Muslim community (for acts which we already have laws against). It was unnecessary, and again overtly racist - designed to whip up public outrage and fear, not to address a real gap or problem in our society.
If the CPC wants to come within striking distance of the keys to 24 Sussex again, they will have to acknowledge how they became the Harper Party, and what they did as that party. Then, and only then, can they start to make the broadly inclusive coalition that is needed to ascend to power.