In principle the code works without issue. Can you run the following code and does it error ?
library(tidyverse)
(a_ <- tibble(ID=rep(1:2,each=2),
x1 = 1:4))
(b_ <- a_ %>% group_by(ID) %>%
mutate(returns = (x1-lag(x1))/lag(x1)))
If your session got into a bad state, restart it without reloading workspace i.e. start clean, and try your code again, perhaps it will work.
Perhaps if you have some old package version/versions.
Use SessionInfo() to see a shareable list you can provide here, or you could simply adopt the latest with update.packages()