Careful with "codomain" and "image". Codomain always means a set that contains all values of the function; "image" may mean only the elements that are actually outputs of the function, or it may mean the same as codomain.
"$f\colon [1,5]\to\mathbb{R}$" means that $f$ is
- a function;
- the domain of $f$ is the whole set $[1,5]$; and
- the value of $f$ at each element of the domain is some element of $\mathbb{R}$.
So you can plug into $f$ any number $a$, $1\leq a\leq 5$, and those are the only things you can plug into $f$. And when you plug such a number into $f$, what "comes out" will be a real number.
If $f$ is given by the rule "if $x$ is in $[1,5]$, then $f(x)$ is $x^2$", then $f$ is indeed a function with domain $[1,5]$ and images contained in $\mathbb{R}$, so you would be justified in writing $f\colon[1,5]\to \mathbb{R}$.
Writing "$f=x^2$ and $x=2$" is at best confusing. It's better to write $f(x)=x^2$ (indicating that $f$ is a function with input $x$). Much better is to specify the domain, since a standard convention is that when you write down a formula such as $f(x)=x^2$, the domain is understood to be "all real numbers for which the formula makes sense and gives a real number as an output" (this is very common in real analysis and calculus, for example), so simply writing "$f(x)=x^2$" would immediately imply a function whose domain is all real numbers. To specify domain, you would write something like $f(x) = x^2,\qquad 1\leq x\leq 5,$ or $f(x) = x^2,\qquad x\in [1,5].$
If what you mean to write was something like "$f(x)=x^2$ and $x=2$", then you are describing a function whose domain is $\{2\}$ and not $[1,5]$; so you would not be justified in claiming this function can be described as a function $f\colon[1,5]\to\mathbb{R}$.