Institutions and market makers tend to try and stay delta neutral, meaning that for every options contract they buy or write, they buy or sell the equivalent underlying asset.
This, as a theory, is called max pain, which is more of an observation of this behavior by retail investors. This as a reality is called delta hedging done by market makers and institutional investors. The phenomenom is that many times a stock gets pinned to a very even number at a particular price on options expiration days (like 500.01 or 499.99 by closing bell).
At options expiration dates, many options contracts are being closed (instutitions and market makers are typically on the other side of those trades, to keep liquidity), so for every one standard 100 share contract the market maker wrote, they bought 100 shares of the underlying asset, to remain delta neutral. When the contract closes (or get rid of the option) they sell that 100 shares of the underlying asset.
At mass volume of options traded, this would cause noticeable downward pressure, similarly for other trades it would cause upward pressure as institutions close their short positions against options they had bought.
The result is a pinned stock right above or below an expiration that previously had a lot of open interest.
This tends to happen in more liquid stocks, than less liquid ones, to answer that question. As they have more options series and more strike prices.
No, this would not be illegal, in the US attempting to "mark the close" is supposedly prohibited but this wouldn't count as it, the effect of derivatives on stock prices is far beyond the SEC's current enforcement regime :) although an active area of research