Occasionally I come across lay philosophers who assume that all a priori truths will be necessary and all a posteriori truths will be contingent. Actually, I think Kripke pretty clearly refuted both these claims some time ago. Here I will focus on a posteriori necessary truths, providing one a quick example for those interested.
First some terminology. The terms a posteriori and a priori indicate the manner in which something is or can be known. A truth that is a posteriori is known via sense experience (it depends for its authority on the deliverances of the senses). The contrast is with a priori truths – truths that can be known independently of sense experience, such as mathematical truths, or trivial linguistic truths such as that all bachelors are unmarried (of course some experience may be required to grasp these truths – to grasp the relevant concepts, say – but no further experience is required in order to know that what is expressed is true).
Many necessary truths would appear to be a priori. Mathematical truths are an obvious example: they are both necessary and a priori. But there are exceptions. Consider this statement:
(T) Hesperus is Phosphorus.
According to Kripke (in his Naming and Necessity), proper names like ‘Hesperus’ and ‘Phosphorus’ are rigid designators (in this case, of heavenly objects – the evening and morning stars). A rigid designator designates the same object with respect to every possible worlds (or of you prefer, possible situation).
There is an obvious contrast here with many definite descriptions (roughly speaking, expression of the form ‘the so-and-so’). The description, ‘The brightest object in the evening sky’ may designate the same object as ‘Hesperus’. In which case, given the expressions on either side of the ‘is’ of identity designate the same object,
(H) Hesperus is the brightest object in the evening sky
is true. But it is no necessary truth, for ‘the brightest object in the evening sky’ designates other objects with respect to other worlds: those worlds in which it is not Hesperus, but some other object, that's brightest in the evening sky (there's a possible situation in which some other object is brightest in the evening sky, and so a possible world with respect to which (H) is false).
But now consider the identity statement (T). In this case, both terms flanking the ‘is’ of identity are rigid designators, according to Kripke. Of course. ‘Hesperus’ and ‘Phosphorus’ might have been used as names of different objects. That these expressions are used to refer to those, rather than other, objects is a contingent fact. But, using the name ‘Hesperus’ as it actually functions, it picks out that same heavenly object with respect to every possible world.
But (T) is true, it cannot be false. For it's falsity would require there be a possible world in which either ‘Hesperus’ or ‘Phosphors’ designate some other object – and that is impossible given the expressions are both proper names, and thus, according to Kripke, introduced as rigid designators of the objects they designate.
So it would appear that:
(T) Hesperus is Phosphorus
is not a just true, but necessarily true. And yet, in order to know that it is necessarily true, we need to know that it is true, and to know that we need to do some astronomy. That Hesperus is Phosphorus is a posteriori knowledge.
Of course, as Kripke acknowledges, we can truly say ‘But Hesperus might not be Phosphorus’ in the sense that science might yet reveal we have made an (unlikely) error. Here is a kind of contingency (Kripke calls it epistemic contingency). But it is entirely compatible with it's actually being a necessary truth (true with respect to all possible worlds) that Hesperus is Phosphorus. Compare a mathematical example. We can truly say ‘12 × 12 might not be 144’ in the sense that we might have miscalculated. That 12 × 12 = 144 is epistemically contingent. But it is still a necessary truth (true with respect to all possible worlds). And so too, it seems, is Hesperus is Phosphorus. It's an a posteriori necessary truth.