How to deal with advisor writing a thesis chapter for you?
A few possible reasons:

The advisor is not very experienced with advising students and is not clear on what they are supposed to do.
The advisor intends to publish the thesis with the student and is therefore interested in ensuring that the specific chapter is properly written.
The advisor is not confident in the student’s ability to correctly formulate certain ideas.

What can the student do? Ask the advisor politely to lead the writing of the thesis, write a first draft that they can later review. If the advisor insists, I suggest letting it go. It’s one chapter and is not a very big deal if it is indeed an undergraduate thesis. Helping students write is not unethical unless the student is really not leading the project. However in that case I fail to see why the advisor would take the thesis writing as their own project...