There is no “magic rule” that allows you to type \lim to get the standard symbol and \lím to get the accent.
The command \lim has its own definition that eventually produces “lim” in upright medium font face, with appropriate positioning of the subscript, depending on the current math style. If you type \lím you get the same as
\l ím
because í cannot (in pdflatex) be part of a control sequence name (OK, this is not the full truth, but it's enough for this case). The error you get is because TeX doesn't like \l (the command to get ł in text) in math mode. You'd get a different error message if you had
\usepackage[T1]{fontenc}
What you need is to redefine \lim to get the accent. But, if you write in Spanish, you should do
\usepackage[T1]{fontenc}
\usepackage[spanish]{babel}
and the dreaded accents will appear.
Why “dreaded”? Because “lim” is not an abbreviation of a Spanish word, but started its life in mathematics from the Latin word limes. Similarly for other symbols.
Would you denote the iron element in chemistry with “Hi” instead of “Fe”? It's exactly the same. Symbols accepted in a scientific community are independent of the language.
This said, you can easily switch between the two possibilities.
\documentclass{article}
\usepackage[T1]{fontenc} % necessary for Spanish
\usepackage[spanish]{babel}
\usepackage{amsmath} % necessary for math
%\unaccentedoperators
\begin{document}
$\lim$\par
$\limsup$\par
$\liminf$\par
$\max$\par
$\min$\par
$a\equiv b\pmod{n}$
\end{document}

If you uncomment the \unaccentedoperators line, you get

Unicode engines
If you use either XeLaTeX or LuaLaTeX, you should use fontspec and remove \usepackage[T1]{fontenc}, of course.
There's no point in having a preamble that “works” for 8-bit and Unicode engines, because it is essentially impossible to have a document that runs unchanged in both situations except, perhaps, for very simple documents.
Well, one could think to do something like
\documentclass{article}
\usepackage{iftex}
\iftutex
\usepackage{fontspec}
\else
\usepackage[T1]{fontenc}
\fi
% other packages
%%% settings
\iftutex
% settings for XeLaTeX or LuaLaTeX
\else
% settings for pdflatex
\fi
\ifluatex
% settings for LuaLaTeX
\fi
\ifxetex
% settings for XeTeX
\fi
For instance, font loading for XeLaTeX might be different from LuaLaTeX (there are keys specific for either engine). However, my experience is that this is hopeless in most cases.
More important is to see whether you can do something about polyglossia instead of babel.
\documentclass{article}
\usepackage{fontspec}
\usepackage{polyglossia}
\usepackage{amsmath} % necessary for math
\setmainlanguage[spanishoperators]{spanish}
\begin{document}
$\lim$\par
$\limsup$\par
$\liminf$\par
$\max$\par
$\min$\par
$a\equiv b\pmod{n}$
\end{document}
Here's an extract of the documentation to see what values spanishoperator can receive.
