There are actually two modalities involved: the obvious (logical or metaphysical) modality invoked by "necessarily" and the epistemic modality invoked by "known".
In possible worlds semantics for modal logic, "necessarily p" is interpreted the claim that p is true in every possible world. In epistemic logic "it is known (by some agent) that p" is usually interpreted as "in every world compatible with what the agent knows, p is true". So, the tricky bit here is how these two modalities interact when combined.
Using N to abbreviate "necessarily" and K for "it is known (by some agent)" the two sentences have the following forms:
- N(If K(p) then p), and
- If K(p), then N(p).
However, p is being used schematically here, so there is really a hidden universal quantifier over propositions. Incorporating that insight into those two forms yields the following:
1'. N(For all p(If K(p) then p)), and
2'. For all p(If K(p), then N(p)).
Recognizing the implicit quantification over propositions is what yields the connection to the de dicto/de re distinction. While (1') predicates necessity to the whole quantified sentence, (2') predicates necessity to a subformula of the quantified sentence -- the consequent of the conditional. So (1') is de dicto while (2') is de re since it moves the necessity operator into the scope of a quantifier.
In possible worlds terms, (1') says that every world is such that every proposition p, known by an agent in that world, is true in those worlds compatible with what the agent knows. (2'), however, says that every proposition p is such that if it is true in all worlds compatible with the agent's knowledge, it is true is every world whatsoever (not merely the one's compatible with what the agent knows).
This point can be made more clearly, I think, if we consider generalized quantifiers, popular in linguistics and closer to the ancients' syllogistic understanding of quantification, rather than the first-order objectual quantifiers familiar from logic. With generalized quantifiers, a quantified noun phrase like "every boy" is taken to denote the set of sets with all boys as members. So, "every proposition" is the set of sets with all propositions as members and "every known proposition" (again relativized to a particular agent) is the set of sets with all known (by that agent) propositions as members. This yields the following interpretation of (1) and (2):
- 1''. Necessarily, every known proposition is a true proposition.
- 2''. Every known proposition is a necessarily true proposition.
Since the worlds compatible with what an agent knows are a proper subset of all worlds (except when the agent only knows necessary truths like truths of logic), we can see that (1'') and (2'') say different things about the set of sets of all known propositions. (1'') says that in every world the set of sets of all known propositions is a subset of the set of sets of all propositions true in worlds compatible with what the agent knows -- clearly true. (2''), however, says that the set of sets of all known propositions is a subset of the set of sets of all necessarily true propositions.
Put in simplest terms, (1'') is true so long as you can only have knowledge of truths -- usually taken as definitional of knowledge. (2'') requires that you can only know necessary truths, which is a much stronger claim since it rules out the possibility of knowledge of contingent truths. The only way that (2'') looks plausible is if you take knowledge to require something like infallibile justification, a position called infallibilism and (arguably) held by Descartes. This rules out knowledge of pretty much anything you can't know by means of logical deduction alone. The other way (2'') could be true is if necessitarianism -- the view that there are no mere possibilities and the world is necessarily the way it is -- is true. Neither of these views is very popular, since they have many counterintuitive consequences.