This is a tricky question. The native ear will immediately recognize that "had been remained" is not correct. The had should be followed by a past participle. Remained and been are both past participles; you can use one or the other, but not both.
So, either of these could be used to start the sentence:
- He had been president for 20 years...
- He had remained president for 20 years...
This issue gets tricky, however, when you switch to the passive voice. In that case, you can use he had been followed by a past participle, as in:
- He had been elected 20 years ago...
That's a valid formation, and it's listed as the past perfect passive verb form in this table1:
So, the question becomes, why can the verb elected be used in this way, but not the verb remained?
The key is that the sentence with elected is using the passive construction, but the sentence with remained has an active construction. As Dave Sperling says on his ESL website:
Because subjects of passive verbs receive the action, verbs that cannot have objects (intransitive verbs) do not have passive forms.
If you look up the words in a dictionary, you'll see that elect is transitive, and remain is intransitive, which is why had been remained sounds so awkward to the native ear, while had been elected sounds just fine – although many native speakers might have a hard time explaining why.
Now, you can explain it for them: "It's because remained is an intransitive verb, so it cannot be used in the passive voice."
One of the uses of past perfect is to refer to an event that takes place before another event in the past. For example:
I had written poetry before writing short stories.
PAST EVENT = writing short stories
PRIOR EVENT = I had written poetry
I didn't realize that you had written this until I read the comments.
PAST EVENT = I didn't realize
PRIOR EVENT = you had written this
I could understand the movie only because I had read the book before.
PAST EVENT = I could understand the movie
PRIOR EVENT = I had read the book
I wasn't surprised because I had prepared myself in advance.
PAST EVENT = I wasn't surprised
PRIOR EVENT = I had prepared myself
I had already left by the time you got home.
PAST EVENT = you got home
PRIOR EVENT = I had already left
I had already left when you got home.
PAST EVENT = you got home
PRIOR EVENT = I had already left
The last example above is similar to the one in your example:
- I had forgotten that I was going to read a book, when the guests came home and we started talking to each other.
PAST EVENT = the guests came home and we started talking to each other
PRIOR EVENT = I had forgotten that I was going to read a book
The event of "forgetting" takes places before the arrival of your guests, and the arrival of your guests happened some time in the past.
UPDATE
GregD points out in the comments that the situation described by the sentence:
I had forgotten that I was going to read a book, when the guests came home and we started talking to each other.
is unlikely. I agree with him and I think that a more plausible situation would be:
The guests came home and we started talking to each other, so I forgot that I was going to read a book.
In this case, GregD uses simple past to describe a sequence of events in the past. The order in which these events take place is inferred from the meaning of the sentence. It is also possible to use the past perfect to make apparent what this order is:
I forgot (simple past) that I was going to read a book, because the guests had come (past perfect) home and we had started (past perfect) talking to each other
Best Answer
This is grammatically correct, and probably what you wanted to say. realized is in simple past, so you are talking about something that happened in the past. had forgotten is past perfect, which places it before the realizing.
Note that realize is usually followed by a that-clause, although the that is often omitted.
On its own, this sentence is incomplete. having is a participle, and Having forgotten something is a participial phrase. Remember that realize requires a that-clause, and a phrase won't do. (A clause contains a verb, a phrase does not).
You might use it in a sentence like this, where there is an additional that-clause: