Every time a Pencil tool operation is undone, Figma switches away from the Pencil tool to the Move tool. It would be a smoother interaction and workflow if tool selection would be independent of undo/redo actions.
The current interaction makes the most sense if you think of undoing individual tool operations as correcting mistaken use of the tool (e.g., I wanted to move an object, but instead I drew a new object). But, and this is especially true of Pencil tool interactions, a better model/principle is to think of undo as removing the last object drawn because the user is dissatisfied with the outcome and would like to try again with the same tool. As it stands, someone who discards their last Pencil operation has to reselect the Pencil tool, which is a really frustrating and inefficient experience.