What are the rules of assignment? Recently I've been reviewing some of the basics of algebra, and one thing that is taught rather flimsily are the rules of when we want to 'assign' to a symbol. Is there a formal language that allows us to define an assignment, for example we often see 'if $x=...$ or 'when $x=...$'. The first question that a student might have is 'WHEN precisely is $x=3$' I understand in 'model theory' there exists an idea of 'assignment', but it does not seem naturally possible to link it to the simpler concept, Perhaps here we find the origins of  this concept, but I cannot see it? Likewise, can we use the original 'variable' name? For example 'under the assignment $x=3$, we know that $x^2=9$' in this case we are using the variable $x$ but under a particular assignment. If we can do this, is there any difference between a 'general' expression for the variable $x$ and an expression under an 'assignment'.
 A: The problem here is that in actual practice, we are mixing both mathematical language and natural language, and it's not that the mathematical language or the natural language by themselves are tricky, but rather it's the mixing of the two that cause these concepts to become blurred.
The central bone of contention, as you're observing, is what exactly is the following hybrid of mathematical and natural language (English), in this case:

Let $x = 5$.

What does it say about $=$? Does it mean $=$ is simply a verb indicating that something holds true, or is it something else? What I would suggest is that the above piece of language is formally ambiguous as to its interpretation, but both interpretations can be carried out in a consistent manner, and both of them have been suggested separately in the two answers given here.
The first is that this is introducing a hypothesis. The variable $x$ never actually gets a value. Instead, what is going on here is we are really saying "Suppose it is true that $x = 5$", and for sake of brevity, we use the term "let". That is, we are building what in formal language would look something like
$$(x = 5) \rightarrow \cdots$$
The second is that this statement, by its enunciation, actually does cause the fact that $x = 5$ to become true. That is, "let" expands to "I declare hereby that $x = 5$." This is the assignment version. Linguistically, this type of morsel is called in some circles a "performative": it is a bit of language that causes its own truth simply by virtue of putting it forward. (This is similar to, but not quite the same as, the more commonly-known imperative: an imperative is a command given from one person to another. They both "do something", but the imperative requires further action to cause change, the performative does that all by itself.)
However, there then becomes the question of when and where the assignment ceases being valid, as you point out, since clearly it is not the case that from here on forever and everywhere $x = 5$ must hold otherwise we'd have a heck of a time trying to do maths and everyone would be fighting over what "$x$", a very common symbol, must mean! :)  Hence if you take the assignment picture, you must thus also take the idea of scope. Unfortunately, while there is a semi-common symbol, $:=$, for assignment, there is not a maths-only symbol for a scope. Thus, scopes are still implicit, not explicit.
Insofar as the "rules of assignment", it's basically this:

*

*Declare a scope. (No notation!)

*Make the assignments within that scope.

*Choose this as the scope to do some argumentation, then do the argumentation. In that argumentation, the given assignments are the meanings of the variables.

Outside the scope, the variables' meanings are once more undetermined (or not fully determined). That, I believe, answers your last question: the statement's meaning changes depending on what scope it is enclosed in, but scopes are not written explicitly in mathematical papers. Instead, you have to mentally track them and it's something you just pick up with experience.

ADD: I see some comments that suggest you may be asking for, say, properties or axioms that assignment follows. I'd suggest that there's pretty much only one: once $a := b$ has been enunciated, then $a = b$ necessarily evaluates to "true".

Of course, the relationship between these two approaches is, of course, that once you make the assignment, it becomes a true hypothesis, and thus we can try reasoning forward from it. However, which approach you choose to formulate maths is not something with a single answer. It's a choice. In the strong computer-coding affinity this has, it's basically the difference between functional and imperative programming. In functional programming, everything is in terms of "this relates to that". In imperative programming, you more explicitly issue commands to the computer that make the computer do stuff, like set variables to certain values. Of course, since the computer is ultimately doing stuff, the functional program must somehow become translated to imperative, but it is not written like it is imperative.
That said, I'd still argue in the end that ultimately you can't get away from the assignment: after all, even if we take the hypothetical approach, for the result to have any use, somewhere $x$ ultimately has to get assigned. The trick, then, is that that would happen in a particular application. Like if you're calculating a geometric quantity, your variable assignments happen - again implicitly - as part of the specific problem in question.
A: I would claim that, indeed, in the practice of mathematics, the sign $=$ is used in (at least) three different ways. The tradition is to pretend that there is only one use, that of an assertion of a relationship, such as $2=1+1$.
However, in practice, there is also assignment, as the question observes. So, for example, if we're doing Peano arithmetic, we might define $2$ by "let $2=1+1$".
Also, there are queries or tests, which do not assert a relationship, and do not assign anything. As in "if $x>y$, then...". Yes, we can say that the smaller logical piece "$x>y$" expresses a possible relationship, but it does not assert it. Depending on one's formal logical framework, this may be an empty distinction. However, in dealing with informal logic and basic mathematics, this conceptually distinct.
Some of this is blurred by what are, in my opinion, "fake implications", where one is looking at cases, or making certain assumptions, but expresses it as "if... then...", where, in fact, the "if" component is not in doubt. E.g., "if $x=2$, then $x+x=4$". My quibble could be expressed as, "well, how do we test whether or not $x=2$?". It makes much more practical sense to say "for $x=2$..." or "when $x=2$..." or, again, an assignment: "let $x=2$. Then $x+x=4$."
A: You seem to be thinking about mathematical variables like computer language variables. There are no scope rules. If I say "let $x=3$" I mean just that. It is expected that what I say next will expose a reason for the statement.
In mathematical writing, there is no difference between a declaration and an assignment because the symbols are not names for boxes or references to boxes.
In fact, you probably wouldn't see a statement like $$\text{let }x=3$$.
You would more likely see something like $$\text{let }x\in\mathbb R\text{ be a real number}$$
and later see a statement like $$\text{if }x=3\text{ then ...}$$
A: You want to consider asking on the math educators site if you're specifically interested in how to teach students about $=$ or answer their questions about what it is.
Talking about assigning to a symbol in math is borrowing a metaphor from programming. That's not completely true; let $x$ $=$ something constructions are very old but I think that thinking of them as an assignment rather than a hypothesis is a programming metaphor. You can get a lot of mileage out of this metaphor, but it is not the only way to think about what $=$ is doing and it might be misleading, since $1 + 1 = 2$ is not an assignment. It is possible to lean into the programming metaphor further and use a dedicated symbol like $ := $ for assigning to variables, but that might be counterproductive.
In model theory / the semantics of first-order logic, an assignment has a specific meaning. It is a mapping from free variables to their denotations.
You need this map in order to define the notion of truth in a model.
For example, here is one such rule, giving the meaning of the existential quantifier.
$$ M, \vec{v} \models \exists x \mathop. \varphi(x, \vec{v}) \;\; \textit{if and only if}\;\; \text{there exists a variable assignment $\vec{u}$ extending $\vec{v}$ such that $M, \vec{u} \models \varphi(\vec{u})$} $$
A variable assignment $\vec{u}$ extending $\vec{v}$ means that the variables assigned any denotation at all by $\vec{u}$ are a superset of the ones assigned a denotation by $\vec{v}$ and that $\vec{u}$ and $\vec{v}$ agree on their common subset.
This is kind of unsatisfying though and doesn't really make the intuitive concept of hypothesizing a value for a variable clearer.
The semantics of equality are similarly unsatisfying and appeal to an intuitive notion of equality that already exists in the background.
$$ M, \vec{v} \models t_1(\vec{v}) = t_2(\vec{v}) \;\;\textit{if and only if}\;\; \text{the denotation of $t_1(\vec{v})$ is equal to the denotation of $t_2(\vec{v})$ in $M$} $$
