It’s safe to assume that the Forerunners did not build the giant war machines or Guardians for -Yoink- and giggles, so what specific target were they made for? The Precursors? The Flood? Humanity?
Possibly to defend worlds on which sentient life was seeded? But they were logic plagued and didn’t work?
We were outside of the map, so the guardians kill us. 
The only legitimate thing that we know about the Guardians is that they are the ones that have caused massive destruction to multiple planets…and they’re humongous.
Now some speculation:
They are called the Guardians for a reason, and in the Halo lore, there is some type of library or something that contains all sorts of Forerunner knowledge, and they may be the ones that are allowing access to/guarding this library sort of thing.
> 2533274964458234;3:
> We were outside of the map, so the guardians kill us. 
Ive been killed be a few Guardians in my time but how did i miss it? Its over 4500ft tall lol.
The purpose is to control the craziness of us Spartans. Want to go dinosaur fossil digging? Nope! Guardians will blow you up with land mines. Want to explore the darkness? Nope the Guardians will shoot you in the face with gauss lasers. Think you can swim? Think again! Think your armor can withstand a 10,000 ft drop? The Guardians have some bad news for you. See a spinning grid? Ooh, looks like the Guardians are up to something! They restore the balance
best guess is to guard the domain
My guess the Forerunners initially built the Guardians to protect the Keyships from any possible flood that may have survived after the Halo array was activated, while the Keyships reseeded the galaxy of life. In Halo 5, I believe we will see what their possible secondary reason for being built is for.