Legal, arguably. A halfway decent lawyer could fight this case and win it, especially in a juvenile court- especially if the cop was tailing him for more than those three minutes past midnight, and the minor could prove it.
Ethically, there are several viewpoints to examine, and I'll be drawing my arguments from "The Elements of Moral Philosophy" (by James Rachels and Stuart Rachels, it's this tiny book I needed for the ethics class I took this past semester) if you want to read up more on these viewpoints.
By Ethical Egoism, the officer was simply acting in his best interest, to bolster his numbers, and was therefore doing nothing wrong. Ethical Egoism states each person ought to pursue his or her own self interest exclusively.
The Social Contract theory, on the other hand, believes that morality consists of the set of rules, governing behavior, that rational people will accept, on the condition that others accept them as well. Whether the officer was acting ethically in this case depends mostly on the individual's viewpoint as to whether they'd like everyone to act like the officer.
Utilitarianism, on which a small part of my personal philosophy is based, states that the action that creates the most happiness, or, depending on your interpenetration, the most good (however you define good), is the moral action. In this case, the minor getting home three minutes too late caused no harm (or, view dependent, unhappiness) whereas the officer caused significant unhappiness (or harm).
The Categorical Imperative, as stated by Kant, is thus: "Act only according to that maxim by which you can at the same time will that is should become universal law." Being a moral individual then would require guiding one's conduct by universal laws. By Kant's view, to allow this one minor off for his crime would require all minors be let off for violating curfew, and would therefore be wrong. Kant was very up on these universal, no exception kind of moral laws.
There is also the ethics of virtue, by which we become moral by following various traits in our habitual actions, which may or may not apply here. This can really go either way and we're not given enough information to know whether either party was acting virtuously.
My own views would indicate that: The minor was attempting, to the best of his ability, to comply with the law. Had he been arriving anywhere other than his home, the officer's actions would stand. Secondly, the officer seems to act by the letter of the law but not the spirit- the law is intended to prevent teenagers from getting into trouble at night, whereas punishing the minor for being out three minutes too late, when the intent of the minor was to go home, is not what the law was intended to do. Thirdly, actions of this sort undercut the authority of the general police force- how can you expect the people to trust and rely on you when you take such action for such petty "crimes"? Lastly, I believe the officer should have shown some discretion here, because the law, to my mind, is not a solid wall but a flexible and dynamic force used to enforce the public good- indeed, any manner of governing humans should not be considered a universal, no exception restriction, simply because that is not realistic when you consider how the very nature of humanity is constantly shifting and changing.
TL;DR Punishing an individual for two years for being three minutes late does not support the public good, and therefore is not a moral action, at least to my opinion.