Say that a guy was dating this girl since he was a junior in high school and at the time she was a freshman. Say that they stayed together over the years and he is now 18 and graduated. Is this relationship illegal since he is an adult and she is a minor? Or is this allowed since they started dating when they both was minors?
So as pointed out in the comments, most states do not set 18 as the age of consent (in the U.S. a majority of states have 16 as age of consent. 18 becomes famous because that's the age of consent in California (the world's largest supplier of porn) and the Federal Government, which means if they are looking at an older partner, the FBI gets involved... and usually a state line was crossed.). So for the first part, this is not going to get the 18 year old in trouble.
That said, most age of consent laws do acknowledge and address this question with a "Romeo and Juliet Exception" of some kind worked into the law. These usually allow for exceptions to the age of consent laws if the ages of the couple are within a few years of each other and the older partner is not in a position of trust over the younger (i.e. a student teacher cannot date a student even if there is a three year age difference between the two). Generally, it allows for ages in early 20s to date those in late teens as the difference does occur occasionally, although not often.
iowa based on the OP's profile.
Say that a guy was dating this girl since he was a junior in high school and at the time she was a freshman. Say that they stayed together over the years and he is now 18 and graduated
I understand that to say that she is no longer a freshman* so presumably she is now 16 or older, therfore (and assuming "dating" means having sex) as Iowa's age of consent is 16 I cannot see any offences being committed either now or back when she was a freshman as that link includes this:
Iowa statutory rape law is violated when a person has consensual sexual intercourse with an individual under age 16. A close in age exemption allows teens aged 14 and 15 to consent to partners less than 4 years older.
*According to Google, freshmen are 14 or 15 years old
Dating is not sex (or at least, isn't necessarily sex). There is no "statutory rape" equivalent to dating someone younger than you in a way that does not involve sex or child pornography.
Sometimes, when one person is in a position of trust or authority over another person, and a date (even if it does not involve sex or child pornography) is secured with the express or implied threat of an abuse of that position of trust or authority, this can constitute "sexual harassment" which in U.S. law, is a subset of sex discrimination in most cases (there are a few direct sexual harassment statutes as well).
The U.S. Equal Employment Opportunity Commission defines sexual harassment as, “unwelcome sexual advances, requests for sexual favors, and other verbal or physical harassment of a sexual nature. Harassment does not have to be of a sexual nature, however, and can include offensive remarks about a person’s sex or gender orientation that are offensive and so frequent/severe as to create a hostile work environment or results in an adverse employment decision.”
The definition of sexual harassment in the context of a teacher and student is similar. Sexual harassment is not directly tied to age, although a minor is more likely to be in this kind of situation and the interaction is more likely to be interpreted in this way. But this doesn't apply to people who were friends before and are friends now.
Michigan’s seduction statute provides that “[a]ny man who shall seduce and debauch any unmarried woman shall be guilty of a felony . . . .” Mich. Comp. Laws § 750.532. While this statute could be construed as involving conduct other than sex, the case law appears to have given it a better defined meaning:
Under [the seduction] statute, the offense is committed if the man has carnal intercourse to which the woman assented, if such assent was obtained by a promise of marriage made by the man at the time, and to which without such promise she would not have yielded.
People v. De Fore, 31 N.W. 585, 588–89 (Mich. 1887).
A constitutional challenge to this statute under the precedent of Lawrence v. Texas, 539 US 558 (2003), which generally speaking provides a constitutional right or consenting adults to have sex with each other (absent prostitution), recently failed for lack of proof of standing to challenge the validity of the law.
There may be a few archaic laws on the books which address dating minors, as opposed to having sex with or making pornography with, minors, but I am not aware of any such laws.
Another tricky issue is what happens if someone persists in dating a minor over the objections of their legal guardian or parent. Normally, going to property owned by the parent or guardian for a date over their objection could constitute trespassing, but it would be rare for the legal system to be invoked otherwise and it would not normally be treated by police as crime for a couple including a minor and an adult to date behind a parent or guardian's back, unless it led the minor to runaway or to be statutorily raped.
Statutory rape laws and similar age based regulations of sex and pornography and prostitution exist, of course, but those aren't automatically within the scope of the question about actual dating itself.
It would be rare that a state's statutory rape laws would be structured in such a way that the older person could legally have sex with the younger person at one point, but then it would become a crime later. But, it isn't inconceivable that this might happen.
"Dating" is not a clearly defined concept and almost certainly could not be made a subject of criminal law in the United States without the law being held to be unconstitutional for being void for vagueness. Dating does not necessarily have to include sexual activity, or even any activity other than talking.
Criminal law requires the highest level of specificity in the law itself and leaves the least up to interpretation of judges. Administrative law (e.g. professional licensure) is often very vague, leaving enforcement agencies with broad interpretation to determine what statutes actually "mean" in real life. Criminal law must be understandable without any help by the average citizen.
Any constitutional law banning "dating" would have to be clear on what sort of behaviors cross the line from legal socializing to unlawful "dating". These laws already exist - they are your basic local laws involving sexual assault of a minor and other related crimes such as exploitation and manufacturing sexually explicit imagery. The difference is that these laws do not generally use the term "dating" or "date", rather simply enumerating the specific prohibited behaviors directly.
So, if you want to know if a particular relationship is "legal", the statutes in question that need to be consulted are the behavioral ones. What are the exact behaviors intended (sexual intercourse? sexual fondling? passionate kissing? just holding hands?) and what laws exist banning such behaviors for persons with the applicable age difference?
This analysis, of course, does not include the social ramifications of an adult being romantically entangled with someone of a much younger age, which can be serious even without explicit criminal penalties.
In response to a comment by ohwilleke, I am aware that a legislature could pass a law concisely defining "dating" for purposes of criminal and/or civil law. This would not really change the situation as it would simply be an alternative way to phrase existing laws regarding sexual assault or misconduct rather than a new regulatory concept. For another way to put it, if State X passes a law against murder and State Y passes a law against "doing a jerkhole" with the definition of "doing a jerkhole" being "the act of committing murder", then that is a distinction without a difference. The same acts are prohibited, it's just that State Y phrases it in a more convoluted manner.