I believe the “Valid for: Italia” on the visa stamp is no big deal. It always says so because your visa is not valid, e.g. to study in Sweden the whole time. But (all?) D visas really are valid for short-term travel to other Schengen countries and also exempt the holder from any short-stay visa requirement when crossing an external border. At the same time, there are still very conflicting info about this from official places (e.g. this) and I don't know all visa types from all Schengen member states (there are hundreds…) so I can't offer any guarantees.
Beyond that, the Schengen Borders code explicitly allows long-stay visa holders to enter the Schengen area elsewhere. See Flying to a Schengen country different from the one that issued a D-type visa Travelling through Italy (crossing the external border at an Italian airport and then taking an internal Schengen flight) definitely isn't required but because using an Italian visa in Italy is unproblematic and there are no border checks between Schengen countries once you have entered, it would of course be much easier in practice.
There is also a distinction between entering another Schengen country on the way to Italy (e.g. transiting in a major airport like Frankfurt or Amsterdam) and just using the visa to go in and out for a short trip. If you are transiting (and have the tickets to show it), border guards can exempt you from some requirements and would generally be less worried about the fact that you have a visa for Italy.
On the other hand, if you come for a short-term visit, directly from your country of residence and without having ever set foot in Italy, they might be concerned that you are really trying to abuse the visa and have other plans (like working illegally in Sweden instead of studying in Italy) and therefore interview you a bit more thoroughly than usual.
Note that when you go on a visit to another Schengen country, you are supposed to fulfil all the usual requirements for short-stay visits. It would therefore be useful to gather all the documents you would need for a visa application and have them with you when crossing the border. In particular, you need to be able to articulate your purpose clearly and credibly, know where you will stay, why you are coming to Sweden, what you want to do there, etc. But if you look like you have no money, cannot establish your intent to go to Italy in the future and have no idea where you want to go or tell a story that makes little sense (say pretend you want to do tourism but only have accommodation in some random small town), border guards are likely to deny entry.
Also, you are telling us you want to go for a couple of days to Sweden, return to your country and then back to Italy. Personally, I have no reasons not to believe you but you do need to realise it might sound a bit odd. Five months is not a very long time and it seems you haven't started your study yet, so when does your course in Italy start? Why the sudden interest in a country that's very far from Italy and not necessarily on everyone's to-visit list? Have you been to Europe before? And why the trip back home instead of going directly to Italy? Be prepared to account for all that as well.
But, legally speaking, crossing the border with that visa is in any case allowed. In fact, if it were not, the rest would be moot and border guards would have practically no choice but to deny entry. It's only if the visa really is valid for other countries than Italy that the details (your intent, etc.) become relevant to their decision. And, while the law allows them to check everything I mentioned, it's also possible that Swedish border guards won't care that much and just stamp you in without asking anything.