Answer
Can I get financial compensation?
Can you first quantify in euros how much damage you suffered from detention? If yes, consult a lawyer asking if there is any rule granting you compensation. If no, you can't demand anything.
Quantification can be done by any means, like missed connection and suffered costs. Despite any formula, you need a monetary result.
I've already got an email address to send a complaint to.
Yes, you can politely address the issue to the manager. I hope they gave you a real, official and monitored address.
Raising flags and suspicion
Border officers look for exceptions to the norm, because that is where the cases they are paid to find usually dwell (cit. @JimMacKenzie)
The problem here is that the immigration officers were simply doing their jobs and were alerted by important alert flags that you have raised with them during primary inspection.
- You were trying to enter the Schengen area without a passport. This is not usually a concern, but some kind of soft flag. There are a number of countries that accept national IDs rather than passports. An officer looking at your ID has the right to ask where you are coming from. And you have the right to explain why you can travel without owning a passport. For example, you could be coming from UK which is still EU. Milan (Malpensa?) is a very large airport with plenties of destinations. A lot of people fly without passport without concerns.
- You (claimed you) were coming from Ukraine. Ukraine has no agreement with Italy for recognition of ID cards (unlike Moldova-Sweden). This is a serious yellow flag at this point. The officer knows that in order to arrive from Ukraine you have needed a passport there. Need to investigate!
- You (claimed to) have left the boarding cards on board. Along with the two above, you triggered an alarm in the officer's mind. Now, it is true that you have no obligation to keep your cards until exit from the airport. But you just collected 3 alert flags in a single shot!!
Since you had 3 elements of suspicion, questioning was a bare minimum. You did not mention yours and the officers' behaviour in the conversation. You politely but firmly demanded to be allowed to enter Italy according to Schengen rules. Okay, let's assume politely... but when a person firmly claims a right on legal standings, I would immediately summon my manager or my legal office!
It is my assumption, from the interpretation of the question, that you were just standing on your legal point without trying to explain the particular situation. Particularly because you were allowed a connection in KBP without a transit visa. I think (again, it's my thought) you just repeatedly answered them "Why the heck do you need a passport when I am European?", instead of cooperating with the police explaining how your situation was special on your favour.
During your detention, they might have done additional checks without telling you, like criminal records, arrest warrants etc., just to make sure there was no reason to drag additional attention on you. They could have even phoned the Swedish embassy to clarify, or their legal team. Who knows. In the end, you were rightfully released as expected.
There was no reason to hold you indefintely, but it took them some time to determine you are welcome.
An example
Following is mere speculation.
To help you understand why it was important in such a situation (not just a Swede entering Italy without a passport, but the above 3 flags all together), let me try to enter the officers' shoes and provide examples.
You are a passenger standing next to me with a Swedish ID card after a flight from Ukraine.
Could you have bribed someone to let you board the aircraft's illegally (even along the baggage?) and then emerge at destination? That might explain your lack of boarding cards. Investigate!
Could you have given your passport to someone looking like you to continue traveling on your name? Investigate!
Is it possible that your passport has been recently confiscated, but not your ID, under a criminal prosecution in order not to leave the country? Call embassy, investigate!
Yet again, that is speculation.
Conclusion
In the end, I hope that you will have a polite written conversation with the officers' management. You will unlikely get real apologies for what happened, but maybe they will explain to you why your situation demanded additional attention at the airport.