This is one of the big problems with chivalry, and one that has had entire books written about it. The best is Matthew Strickland's War and Chivalry: The Conduct and Perception of War in England and Normandy, 1066-1217, and most books about chivalry have at least one chapter going "Wait a minute, what's with all the murdering?" On the one hand, noblemen were supposed to be, well... noble men, and a part of chivalry was protecting the weak. But a large part of their job was to kill people. Many of the most chivalric men of the Middle Ages were also known for acts of reprehensible violence. Godfrey de Boullion, who became leader of the First Crusade and was venerated for centuries because of it, presided over the worst massacre in living memory when the crusaders took Jerusalem in 1099. Although the massacre had plenty of supporters, there were also many who were horrified. Charlamagne, also seen as a role model by the medieval nobility, massacred thousands of captives at Verdun. Honestly, we're still not sure exactly how this worked in terms of justification, but the mostly likely explanation is that knights planned to make up for it with penance and charity.
One of the big problems in studying this is that the standards could fluctuate quite drastically. In the early thirteenth century, chevauchée tactics were out of favour and viewed as immoral. The sources from the period really don't like discussing them at all, let alone in favourable terms. By the 1250s, however, they were back. We don't really know why, and there isn't the density of evidence needed to accurately track public opinion regarding the moral acceptability of the chevauchée. For example, there was a highly regarded nobleman called William Marshal, who was active from the end of the twelfth century until his death in 1219. Marshal was campaigning in France under the command of King John. John ordered Marshal to lead a dawn raid on the camp of a French army, which he did. In the course of this attack, Marshal and his fellow knights killed hundreds of unarmed camp followers. Some of them were women, others were old, others were injured, many were killed in their sleep. It is somewhat telling that The History of William Marshal, a biography written in the years after his death, completely leaves out this campaign. Marshal and his men would not have done it if they found it abhorrent - but even by the 1220s this had aged very badly. Marshal himself seems to have been aware of these changing standards. In his younger days he was openly accepting of chevauchée tactics, and encouraged King Henry II to use them, but in 1217 he ordered his army to disband and sent his knights to their castles until further notice after they looted the city of Lincoln while he was in Nottingham talking to King Henry III. It demonstrates that although medieval noblemen could be very violent, there was a limit to what was deemed acceptable, and even within a single person it could change quite a bit over time.
Let's look at the idea of "civilians". Although people in the Middle Ages did not have the same concept of civilians and combatants as we do, they did make some distinctions, and it's clear that attacking certain groups of people would be condemned. In the 10th century a movement began called "The Peace of God", that encouraged people to view church land as off-limits. The Peace of God movement did not achieve all its aims, but churches did come to be seen as places of safety and refuge that knights were generally reluctant to enter while armed. They also tended to draw a distinction between armed and unarmed opponents, and the killing of unarmed people was usually frowned upon, and it certainly wasn't glorious. In chivalric tales like The Song of Roland, it is normal to see the hero honourably permit an unarmed enemy to either flee or grab their weapon before any attack takes place, and they don't kill innocent people. In the real world, attacks on Jews were usually condemned, with anti-Semitic crusaders described as "insane" and "rabid" by medieval authors. Attacks on clergy were roundly condemned, not least by the papacy. And there were also men like Thomas "the most accursed" of Marle, who was so violent that he was the subject of a manhunt in 1130 led by the French royal family, because he was deemed to be a sadistic madman that needed to be killed for the good of the French kingdom. The author Guibert of Nogent, who knew Thomas personally, said that Thomas had convinced him that some people are just born evil, because it was the only way to explain his personality. And yet, under different circumstances, the people condemning these actions would probably do the same. It's worth noting that although Thomas of Marle was condemned in 1130, he was also a hero of the First Crusade. Chivalry and evil could exist in the same person. It's nuts.
One possible explanation, and the one I am most persuaded by, is that knights viewed morality as a balance sheet. They thought they could make up for the bad stuff with penance, charity, and perhaps a holy war. They may have thought "Well I've killed 80 people in this campaign so when I get home I'll found a monastery and give to the poor". Knights did this a lot. It was extremely common for knights and noblemen to make donations to local monasteries immediately before or after a military campaign. Perhaps the most drastic example of this was Bertran de Born, a troubadour and nobleman of the 12th century known for his bombastic poems and warmongering. Here is a taste of his literary output:
We shall see clubs and swords, colourful helmets, shields pierced and smashed, and many vassals striking together, so that horses of the dead and wounded will wander aimlessly. And when he enters the fray, let every man of rank think only of hacking heads and arms, for a dead man is worth more than a live loser.
And:
A man should never feel sorry for a peasant if he sees him break an arm or a leg or do without something he needs. For a peasant - so help me God- doesn't want to use what has to help even his closest kin, not for tears, not for pity. He naturally shuns any such deed. A low rascally gang, full of tricks and usury, pride and excess! You can't endure their deeds!
So he wasn't big on kindness, and viewed chevauchée not just as a military necessity but a glorious form of warfare. But in his old age he retired to a monastery and gave all his money to charitable causes. One of his last poems laments the shortness of life, exhorts the kindness of God, and begs forgiveness:
What is man, when I think about it, and what is he worth? I value myself as nothing. And why does man then pretend to be mighty? Is he mighty? No, he falls far short, so feeble is his effort on the day he goes through the passes where all, without exception, must go. Whoever may pretend to be care-free or admire himself, common to all is death.
To the lord, who is the fulfilment of all joys, I pray that He may reign among us. My poor heart! How it oppresses me, when my sighs remind me of treacherous and false delights. But now my destiny is changing for the better, so let Him not visit His wrath upon me. Some may mock me, but I am alive, and they'll be dead.
This might not have saved his historical reputation, but he hoped it would save his soul (though he continued to write violent poetry until the Cicstercian Order banned its monks from writing poems in 1199, which may have been entirely because of Bertran!). It was extremely common for knights to sponsor ecclesiastical institutions and ask for prayers for their soul. Many knights did know that what they did was wrong, they just thought they could make up for it by sponsoring a convent or a church or giving to the Knights Templar.