Personally, I think the easiest way to think of it is that normally when you have something that modifies a definite noun, you place it between the article and the noun, but if you want to place it elsewhere you have to repeat the article with the modifier (which then tells you that it goes with the noun). So with an adjective:
? ἀγαθὸς ἀνή? or ? ἀνὴ? ? ἀγαθός
In your examples, the modifiers aren’t adjectives but it works the same way:
As for function, I don’t think I can explain this clearly but I’d say that often the version with the repeated article answers the question “which one” so that ? ἀγαθὸς ἀνή? tells you what kind of man while ? ἀνὴ? ? ἀγαθός tells you which man (and of course in some cases there might not be any real difference between the two).