Here is what John Mueller said:
Google will use the most restrictive setting you have on the page (this matches how robots meta tags are generally processed, eg if you have a “noindex” + “index”, then the “noindex” will override the “index”). If you have a “nofollow” in static HTML and remove it with JS, Google will still use the “nofollow”. Similarly, if you don’t have any robots meta tag, and add a “noindex” with JS, Google will use the “noindex”. In short, adding a “nofollow” via JS would work, removing it won’t.
Google goes with the most restrictive signal they get here.
Forum discussion at Reddit and Twitter.