I mean... yes, that's part of the in-universe reasoning behind it, but the main consideration was always the one you mention as an afterthought: "It's also a quick path to the Dark Side."
Emotions are the path to the Dark Side. The problem is that most of the SW media wants to focus on "good guy" Force Users (i.e. Jedi) who are also "normal" people with normal people concerns and interpersonal relationships.
Maybe things are different in de Disney timeline, I'm not sure on the details there, but I got the impression that they're mostly imitating the old EU in the broad strokes when it comes to galactic history. And as far as that goes: the Jedi were just fine with "attachments" (meaning: personal relationships) of all sorts for the vast, vast majority of the long existence.
Except the Jedi never really were fine with it. Ever. The past allowed more exceptions than the Prequels era but even in KotOR era they still frowned on relationships and attachments.
Unhealthy attachments (possessive feelings) were always considered a bad idea, for (again) th stated reason: they're a quick path to the Dark Side. But Jedi got married and had families. We know of generational lines of prominent Jedi. The Force was, indeed, strong in their families. (As Lucas phrased it in the OT, before he retconned the "no attachments" stuff into the story with the prequels.)
Jedi can have all the sex and children they want. They just can't *care* about them.
What would you do for your children? For people you love? As a Jedi, you must *always* be willing to simply walk out on your family to go solve some problem on the other side of the galaxy and if some terrorist holds your family hostage you must be able to just shrug and get on with your life.
Frankly? Being a Jedi is a betrayal of your family because you will always be prioritizing others over that family.
We know of two periods when relationships were forbidden (or, in the latter case, very much frowned upon): the Post-Ruusan Old Republic, and the period around Revan's time. (Which, from a Doylist perspective, is because those games were made when the Prequels were also coming out, and the creators were trying to adhere to Lucas's vision.) But for the rest of galacic history? As far as anything we're ever shown goes, Jedi had no problems with relationships and marriage at all.
Except those are the only two time periods where we actually get to see the established Jedi at any kind of scale.
It's never made explicit, and Lucas presumably didn't mean it to be seen like this, but it's interesting that the predominance of the "relatinships bad!" crowd within the Jedi Order, in both cases, saw the fall of a prominant Jedi military leader to the Dark Side. One might infer (or at least theorise, as I do) that the dogmatic approach to this matter works for most Jedi -- at least under normal circumstances -- leads to unhealthy emotional repression among at least some Jedi during stressful periods.
Basically: if the Jedi had just been allowed to get married, Anakin and Padme could have been fine, because without the need for secrecy, he could have just asked for the guidance he wanted, without having to talk around the subject.
The Jedi failed when they allowed Obi-Wan to train Anakin in the first place. Anakin never should have been trained by the Jedi Order of that time.
And if he was going to be trained, he should have been handed to a Master who was both able and willing to break him down and rebuild him from the ground up. Obi-Wan took him out of his attachment to Qui-Gon.
And no, Anakin and Padme being allowed to be publicly married wouldn't have made everything fine. Padme was a sitting Senator, and a prominent one at that. Anakin was a Jedi and (later) General. Any Jedi involvement (especially Anakin) with anything involving Padme inherently creates the appearance of impropriety.
For all that Padme's situation played a role in Anakin's fall, it was his friendship with Palpatine that actually caused him to fall. Padme was a lever to move Anakin but she was far from the only one.
So, in conclusion: I personally view the "no attachments" thing as a fatal flaw of the Order; a sure sign that the manipulations of the Banite Sith have caused the Order to stagnate and calcify. Rigid, unflexible "one-size-fits-all" mandates have snuck in, and this weakens the Jedi immensely.
Attachments are the fatal flaw of the Order. Especially in canon. Obi-Wan's attachments to Qui-Gon and Anakin. Anakin's to his mother, Padme, and Palpatine. Luke and Leia's attachments to Kylo.
And EU? Well there is a reason that it seemed like every second "Jedi" fell to the Dark Side and went evil; and it was virtually always their attachments.
Something else that you say also plays into this:
This attitude also reflects the position of the "Late Republic" Jedi, and while you (seem to) agree with this sentiment, it actually shows how far the Jedi have fallen. They've become agents of the government, rather than agents of justice.
The Jedi are, explicitly, Knights of the
Republic and have been all the way back to KotOR. Not "Knights of the Lightside" or "Knights of the Force" but of the Republic. They swore their loyalty, fealty, and service to the Republic. So yes, by definition, the Jedi were agents of the government (well the polity as a whole).
A true Jedi -- from the better days of old -- would free a slave on sight, and consequences be damned. Anyone who allows a den of sex slaves to exist deserves the consequences.
And they would fail, spectacularly, at being a Jedi or even being an agent of the Light Side.
A Jedi frees the sex slaves, and in the process makes their lives better. Or a Jedi ignores the sex slaves and as a consequence one of those slaves leads a slave revolt that frees a trillion slaves across a thousand worlds and establishes a strong anti-slavery political bloc that lasts for generations.
Tell me, is the Light Side option to free the sex slaves in front of you or to ignore them and as a consequence free trillions over centuries to come?
To act out of rage, disgust, or even moral belief is to
fail as a Jedi. A Jedi is supposed to act as an agent of the Light Side and with the goal of advancing the Republic as it is the most effective means of bringing the greatest amount of good to the greatest number of people over the greatest amount of time.
That's the difference between "following orders" and "doing what's right".
A Jedi Knight, at the very heart of it, must be "the one who does what is right". Luke is a better Jedi, in the end, than anyone we see in the Prequels. And I think that's at least somewhat intentional. The prequel-era Jedi have become enchained and constricted by dogma and bureaucracy. Same as the Republic they inhabit! And in both cases... it's fatal!
Luke is a
horrible Jedi whether you go by canon (Disney or otherwise) or Legends. He's a powerful Force user and an at least decently good person, but by any standard you care to use he fails as a Jedi.
---
You are basically doing exactly what I am taking issue with. You conflate the Light Side with the Jedi and "good" with both as well.
All Jedi utilize the Light Side of the Force.
Using the Light Side of the Force doesn't make you a Jedi.
Good and evil are inherently subjective terms and have no direct bearing on either the Force or the Jedi.
The Dark Side is all about individual desires, individual goals, and individual advancement. Personal advantage at the expense of the community. It's neither good nor evil in and of itself. What it is, is spectacularly selfish.
The Light Side is all about the advancement of the community. Communal advancement at the expense of the individual. Again neither good nor evil, just spectacularly uncaring about the individual.
From a societal perspective, the Light Side will of course be seen as Good. Following the Light Sides tenets results in a more stable, prosperous, society and as a consequence results in a generally better life for most people.
Trying to build a society around the Dark Side can never work in the long term. It inherently becomes a society devoted to serving the will of whomever is at its top.
---
A Light Sider with attachments is perfectly acceptable. You can marry, raise children, and generally just live a good life while also being an active user of the Light Side.
What makes that situation acceptable is that the Light Sider probably won't face any situations that seriously threaten their fall.
Take Anakin, he could have spent his life on Naboo living with Padme, working on starship design/repair, with his mother living down the street, and raising a couple of kids. He would have been perfectly content, very unlikely to fall, and probably a stabilizing and strengthening presence in his community.
Even if some random pirates decided to attack his family and he used the Force to flay them alive, well he would still probably be just fine and isn't at any great risk of falling to the Dark Side.
But as a Jedi? That's an impossibility.
Every moment he is with Padme and the kids is a moment where he is choosing
not to intervene in any of the thousands of situations that could benefit from a Jedi.
Being a Jedi comes with the power, totally ignoring the Force, of life and death on a galactic scale. You are trusted to decide issues of literally cosmic importance.
A Jedi with attachments is a Jedi who can't be trusted to act impartially and so weaken the community as a whole. It is inherently antithetical to the Light Side.
If Anakin insisted on being with Padme, he should have left the Order. But he decided that he wanted the power that came from being a Jedi and wanted Padme; to the detriment of both.