Your question raises the general issue of what it is to treat humanity, unacceptably according to Kant, merely as a means. I attempt to answer this in 1. To point the contrast in 2. I consider what it is acceptably to treat humanity as a means, again on Kantian lines. Lastly in 3. I take up the point about the compatibility, as Kant sees it, of punishment with treating humanity acceptably as a means.
1. What do we do when we treat humanity merely as a means?
'He used me !', I might say angrily when someone deceives me through feigned friendship to disclose information or to 'borrow' money he had no intention of returning. 'Sure he suckered up to her. He just used her to get promotion'.
'He spiked the guy's drink just to use him sexually'. What pulls these examples together as cases of using people merely as means ?
We use their humanity merely as a
means, on the other hand, if we get them to adopt plans they would not
otherwise have adopted by trickery, deception, or illegitimate threats.
The underlying idea here, I suggest, is that treating persons as ends is
a matter of treating the choices and plans they adopt free from these
kinds of manipulation - their values, if you will - as at least ceteris paribus worthy of pursuit, the ends they set as worth attaining. What it
forbids, at least in reasonably propitious circumstances, is manipulation by deceit and illegitimate coercion. And so, in our dealings with
others, we are to seek, so far as possible, voluntary accommodation in
which we can both achieve what we, in the end, choose. When we treat
others merely as means, we achieve our own ends by treating theirs with
indifference or worse. (William Nelson, 'Kant's Formula of Humanity', Mind, New Series, Vol. 117, No. 465 (Jan., 2008), 85-106 : 97.)
2. What do we do when we treat humanity acceptably as a means?
When I buy something in a shop, I use the assistant as a means. When I purchase something on the internet, I use the seller as a means. When I ask someone to take me to hospital and they oblige, I use them as a means. Kant has no objection to this. You will already know this, I guess, but what conditions are met in this acceptable kind of use of others as means ?
Kant's injunction that we treat humanity as
an end, never simply as a means. Consider, first, what it might mean, literally, to treat humanity as a means. In accordance with FA [Formula of Autonomy : 'choose only in such a way that the maxims of your choice are also included as universal law in the same volition' : G 4: 440*], Kant conceives beings with the capacity of humanity as beings who are free to
adopt plans of action, maxims, and thereby set themselves to act in one
way or another, to achieve one or another purpose. But, any of us, from
time to time, may have an interest in how others act, and we may wish to
influence their choices and plans for the sake of our own ends or purposes. Think of that as using another's humanity- the capacity to set an
end - as a means, and notice that it is possible just because persons not
only have ends and plans, but are able, by 'self-legislation, to modify them
in light of further information or reflection. However, we do not use others simply as a means if we get them to behave as we wish by appealing to
their own reason, openly avowing our own purposes and seeking to coordinate with them in mutually satisfactory ways. Perhaps we offer to compensate them for their trouble, or try to find a way to achieve our
purposes jointly by working together. (William Nelson, 'Kant's Formula of Humanity', Mind, New Series, Vol. 117, No. 465 (Jan., 2008), 85-106 : 97.)
*McGregor translation. Paton expresses FA more concisely : 'So act that your will can regard itself at the same time as making universal law through its maxims' (H.J. Paton : The Moral Law, London : Hutchinson University Library, 1948, 33.)
3. Punishment and treating humanity acceptably as a means
So now for the question, Isn't punishment a star example of treating someone unacceptably merely as a means? This question would not bear on Kant’s ethics if he did not endorse the institution of punishment but in fact he does so as is clear from The Metaphysics of Morals, 1797, Part I, § II ‘Public Right’.
To fix ideas: ‘Punishment is a harm inflicted on a person by an appropriate authority because the authority ostensibly believes the person is guilty of doing something wrong or illegal’ (Allen W. Wood, Kantian Ethics, NY: Cambridge University Press, 2008: 208).
If Kant were to justify punishment in terms of deterring others, or of satisfying the public’s demand for vengeance, or of making the public feel safer, etc., then he would be using the punished person as a mere means to such ends. But this is nothing like his justification of punishment.
Jeffrie G. Murphy clarifies the key points:
Kant offers a theory of punishment which is based on his general view that political obligation is to be analysed in terms of reciprocity. If the law is to remain just, it is important to guarantee that those who disobey it will not gain an unfair advantage over those who do obey voluntarily. Criminal punishment attempts to guarantee this, and, in its retribution. it attempts to restore the proper balance between benefit and obedience. The criminal himself has no complaint, because he has rationally willed or consented to his own punishment. That is, those very rules which he has broken work, when they are obeyed by others, to his own advantage as a citizen. He would have chosen such rules for himself in an antecedent position of choice. And since he derives benefit from them, he owes obedience as a debt to his fellow citizens for their sacrifices in maintaining them. If he chooses not to sacrifice by exercising self-restraint and obedience, this is tantamount to his choosing .to sacrifice in another way – namely by paying the prescribed penalty. (J.G. Murphy, Kant: The Philosophy of Right, London: Macmillan, 1970: 142-3.)
Punishment in other words is a debt owed to the law-abiding members of a society; and once the debt is discharged, the punishment undergone and completed, the criminal returns to society as an equal member.
Whatever one thinks of this theory of punishment it needs to be remembered (a) that it applies only in the civil state that Kant outlines in The Metaphysics of Morals and is not defeated by actually existing institutions of punishment; and, more important, (b) there is no trace in it of using one person purely for the benefit of others. Requiring someone to discharge a debt, which is how Kant views punishment, oddly you may think, is nothing like treating someone as a mere means. Kant’s theory is different from, and deeper than, this – whatever its ultimate validity.
References
I. Kant, Groundwork of the Metaphysics of Morals, tr. M. Gregor, Cambridge: Cambridge University Press, 2012.
I. Kant, The Metaphysics of Morals, rev. ed., tr. M. Geegor, Cambridge: Cambridge University Press, 2017.
J.G. Murphy, Kant: The Philosophy of Right, London: Macmillan, 1970.
William Nelson, 'Kant's Formula of Humanity', Mind, New Series, Vol. 117, No. 465 (Jan., 2008), 85-106 .
H.J. Paton, The Moral Law [tr. of Groundwork], London : Hutchinson University Library, 1948.
Allen W. Wood, Kantian Ethics, NY: Cambridge University Press, 2008.
what does it mean to treat someone as an end rather merely a means?
(you can search for them in google more easily than SE's own search function in my experience).