Why are romantic events sometimes called "flags"? Anyone familiar with dating sims and romance visual novels will recognize the term "flag" in that context. In these games, when you are presented with choices which affect how the other characters view you and potentially change which route you go on, it's called a flag. "Raising a character's flags" essentially means that you make choices that improve your standing with that character and which are more likely to put you on his/her route.

This terminology is quite common even outside of visual novels in anime. For instance, the manga The World God Only Knows (a parody of the dating sim genre of games) uses the term frequently, and the manga chapters are numbered as flags (e.g "flag 53"). I've seen it in many other anime and manga as well, both in Japanese and translated into English. I was not able to find any reference for the term used in this way in either English or Japanese.

The term "flag" doesn't seem particularly romantic or descriptive in this context. There are other terms, like "affection points" (a slightly different system) which are easy to understand, but "flags" is at least as common as any of those. What is the reasoning behind the terminology "flag" in this context and where does it originate?
The terminology probably comes from programming. With most visual novel games the terminology "flag" and "counter" go hand-in-hand.

In the background of a game, there are various variables, the most notable ones are the "global" and "local" variables. These variables usually what counters and flags consists of. 

Local variables are usually a point counter that resets every time you start a new game. So let's say you have this character, Y. If you give Y a present, Y's  "affection" counter will increase with 2 points. By the end of the game, if this counter totals 12 points or more point, you will get that character's "good" end.

Global variable are typically flags created by the game to remember certain things. So if in a game if you chose to leave your house without checking the stove, you active the "unchecked stove" flag. Later in the game, the flag is checked and if has been activated, if will trigger the event where your house has burns down and you have to move in with a friend.

A global variable flags are persistent, so when you start a new game they are not reset like local variables. They typically are used as bookmarks to mark progress and be used as save points, so you don't have to replay though everything again. 

Let's say that there is this other character named Z. If you get one of Y's good end, you'll active the Y's good end global variable flag. During your next playthrough at some point dring the game, the game checks for this flag has been activated and if has, you get a new choice that allows you to access Z's route. This is typically done to control player progress in the game as Z's route might spoil story elements in Y's route.