Yes, it's valid English (sort of, see below), but the confusion comes from this: To an English speaker, A and B have a very different relationship between the words, and a very different meaning.
In A, "They stayed three days ago", the three days relates to 'ago'. We're saying exactly how far in the past the action "to stay" occurred, but we do not say how long the stay continued. They might have stayed for two days, or just an hour.
But in B, "They have stayed three days before", the three days relates to 'stayed'. A specific action -- to stay for three days -- happened at some point in the past, and we aren't saying how long ago that happened. It could've been last month or twenty years go.
And B does sound a little awkward, because in that phrase we would normally add the preposition 'for':
- They have stayed for three days before.
This is better, because it makes it more clear that "three days" is in relation to the verb.