Do you have to go to the military to become a detective? No.
When you go into the military you're subjected to testing (ASVAB - Armed Services Vocational Aptitude Battery) to determine the best career fit (MOS - military occupational specialty). This can range from custodian to engineer, infantry to intelligence, etc... You could be manning the 50 caliber machine gun atop a Humvee in the infantry, or developing relationships in foreign countries as a psychological operations soldier. Getting the mos of your choosing is not guaranteed as you have to (1) qualify for the position, and (2) positions must be available.
With that said, going into the military is very helpful if you're pursuing a career in law enforcement. Many law enforcement agencies give preference to military veterans as they've already been subjected to rigorous training and discipline - Massachusetts State Police used to give veterans a 10 point preference on the state police civil servant exam (a non-military individual could score a 97 out of a 100, but the military veteran who scored an 88 will have their score increased to 98 and will be considered first). I always suggest people to consider a career with the Armed Services if you're not really sure where you want to go in life as the military has so much to offer - like retiring with full pension after 20 years of service!
You have a general idea of what you'd like to do with your future. I would encourage you to expand that idea a bit further - do you want to work as a detective in a local police department, work as an investigator for a federal agency such as the FBI/US Marshals/Border Patrol/etc? What about an investigator for the fire department, or with the EPA, state police, or even private investigation? What would you like to investigate - general crimes (burglaries/thefts), drug trafficking, homicides, sex offenses? There's also cyber/fraud/background investigators, and many more. The NFL employs investigators to look into the backgrounds of potential up and coming college players.
I had a college professor who told everyone on the first day of orientation that if you're interested in working as a police officer, including local detectives, to drop out of college (yup, he said to drop out) and apply for a job as a police officer. He explained this stating how you will advance quicker through the ranks if you start early. He then went on to discuss how a college degree will help (even more so if combined with military experience) if you're interested in working at a state or federal level.
So think about what you'd like to do, google the position requirements, and those requirements will help provide guidance in terms of what steps you should take to eventually land that position! If you think of a position of interest but are still uncertain about what steps to take - either write back or submit another question such as "how do I get a job as a (job title)." Good luck!!!