These two questions are resolved in the Consolidated Annotated Rules and in the FAQ.
First, the question of moving a follower from Carc City to a farm
during the game when it is scored due to the placement of a barn is covered in the CAR in a footnote on page 51 (version 5.0) as follows:
Question: Does the placing of a barn, and the subsequent scoring of the farm, count as an opportunity to remove a follower from Carcassonne? The rules currently say that a follower may only be removed to a farm "at the end of the game", but that was created before Abbey and Mayor and the barn.
Answer: Yes: now that farms cannot only be scored at the end of the game, followers from the market can be moved to farms earlier in the game. That occurs immediately after the placement of the barn, and before the farmers are scored.
Obviously, in this case the follower(s) moved contribute to the calculation of the majority in the farm and then the player with the majority scores three for each city (plus pig bonuse(s))
Second, the situation where a follower is moved from Carc City to the farm at the end of play is answered in the Count section of the FAQ as follows:
Can a follower be moved from Carcassonne City to a farm with a barn - and if so, how many points does a player earn (1 or 3)?
Yes, that is allowed: the farmer will then be scored immediately, and so scores only 1 point per city and is (importantly) not on the farm during the final scoring proper.
Hope that helps.