Since Kripke attributed to Kant the conflation of these two notions, it seems worthwhile to investigate exactly how Kant viewed their relation. I posed the paper topic in the form of a biconditional and in terms of judgments: a judgment is a priori if and only if it is necessary.
As I read Kant, 'knowledge' is a generic term covering concepts, intuitions and judgments. These are what Kemp Smith translates as "modes of knowledge." In the Introduction, Kant discusses two such modes, concepts and judgments.
As supplied by our faculty of knowledge, a priori concepts are "original" (A2). That we have a priori concepts can be established by showing what remains when we remove everything empirical from the concept of body. The concept of being a substance or inhering in a substance remains (B5-6).
A judgment brings an intuition under a concept or one concept under another concept. It is an act of the human understanding. (Kant sometimes uses 'proposition' interchangeably with 'judgment,' so that we should be careful not to impute to him the contemporary notion of 'proposition.') At B18, in a discussion of alleged a priori judgments of natural science, Kant states that, beginning with the concept of matter as subject, he "join[s] to it a priori in thought something" not thought in it (and so the judgment is synthetic). Above, at B15, he states that in a mathematical judgment, the predictate is "attached" to the concept. From this I infer that to judge a priori is to unite the elements of the judgment in a way that does not depend on experience.
Regarding necessity, Kant speaks of "necessary judgments" (B3) and "the contingency of judgments" (B4). A necessary judgment is "one which, in being thought, is thought as necessary" (B3). At least one kind of necessary judgment is one which involves a necessary concept. In his example at B4-5, Kant states that "the very concept of a cause . . . manifestly contains the concept of a necessity of connection with an effect." So any judgment in which 'cause' serves as a predicate, as in 'Every alteration has a cause,' is a necessary judgment, because in attaching the predicate concept to the subject concept, we introduce an element of necessity.
There is a normative element in all this. In a necessary judgment, "we are required to join in though a certain predicate to a certain concept" because "the necessity is inherent in the concepts themselves" (B17). Attaching a predicate necessarily to a concept is how we "ought to join them."
Now we are in a position to reformulate the biconditional 'a judgment is a priori if and only if it is necessary.' A judgment's elements are united in a way that does not depend on experience if and only if they are united through the use of concepts which involve necessity.
It does not follow immediately that because experience cannot be the source of a judgment thought with necessity, the judgment has an a priori source. It may be that there are no judgments thought with necessity at all. But Kant thought that he could produce examples of such judgments in mathematics and natural science. Since their source is not in experience, it must be in something independent of experience. And it requires a further step to establish that a source independent of experience can, for humans, only be found in the human mind itself.
Analytic judgments are all a priori, proceeding from the analysis of concepts alone. This analysis rests on the "principle of contradiction" (B15). We can infer that they are necessarily true because their falsehood would imply a contradiction, and hence that we must think analytic judgments as necessary.
For synthetic judgments, the issue is much more complicated, since no contradiction is involved in thinking a concept without the predicate which we attach to it a priori. The only way in which a priori synthetic judgments are thought as necessary is that they hold necessarily of a restricted range of objects, i.e., objects of experience. They are necessary for those objects in that they make these objects possible. In the Preface to the Second Edition, Kant makes these suggestive remarks: "Understanding has rules which I must presuppose as being in me prior to objects being given to me, and therefore as being a priori. They find expression in a priori concepts to which all objects of experience necessarily conform. . . ." (Bxvii-xviii). If the objects necessarily conform to the concepts, then the judgment that they fall under the concept is thought as necessary.
Another argument is one I presented in class and to class members in individual discussion. The idea is to reverse the premise of the first argument, that experience cannot reveal that things cannot be otherwise than they are. Experience also cannot reveal that things as they must be are not so. The argument begins with a large assumption: that a priori judgments and empirical judgments are exclusive. What has its origins in the human mind can never be known through experience, and what is known through experience cannot have its source in the human mind. On this assumption, an a priori judgment cannot be refuted by any experience. If it is true and applicable to experience (as the argument in the last paragraph asserts), it is necessarily true of experience. The notion of limited application of the a priori can be found at A27/B43 and A35-6/B51-2.