Should "the" be capitalized in the middle of a sentence if it's part of a title/name?

Generally, the is an article in front of a noun, not part of the noun itself, so it is not usually capitalized in the middle of a sentence. However, yes, if the is part of the name or title then it should always be capitalized. For example:

The Gambia is situated on either side of the Gambia River, the nation's namesake, which flows through the centre of The Gambia and empties into the Atlantic Ocean.

Here we capitalize the the on the second occurrence of the countries name even though it is in the middle of the sentence because The Gambia is the official name but we don't capitalize the the before the name of the Gambia River because that the is not part of the rivers name.

In the vast majority of cases, the is not part of the name. The president lives in the White House not The White House. The is just the article not an intrinsic part of the name. There are two countries where the is part of their names: The Gambia and The Bahamas. It should be noted that Ukraine no longer, since independence form the USSR, has a the in front of it. Many books, newspapers, magazines and pop bands have the as an integral part of their name. It is particularly common for pop bands. Examples include The Beach Boys, The Beatles and famously The The.

If you are unsure whither the is part of the name/title or just an article before the noun, try Googling the name or looking it up on Wikipedia. In particular, Wikipedia is quite strict about only using the in the title if it is absolutely without doubt part of the name.

A second related question, if the official name does include a the, should you put another the before it when an article is required for grammar and further, is it appropriate to substitute the indefinite article a when relevant. For example, should we say, "I watched the The Smiths on TV last night. I liked the music so I bought a The Smiths album today." or should we say, "I watched The Smiths on TV last night. I liked the music so I bought a Smiths album today."

This is much more complex and subtle to understand. In many cases, people will be unaware that the is part of the official name, and so use the as an article and substitute is as normal in grammar - it would sound clunky for an native speaker to say multiple the, so they would say, "I watched The Smiths on TV last night. I liked the music so I bought a Smiths album today." though technically this is the incorrect grammar that should not be used in an English exam.

If the word the is widely known to be an integral part of the name, such as in The The, then you have to add another article if it is an indefinite article but the definite article would normally be omitted. So a native English speaker would say, "I watched The The on TV last night. I liked the music so I bought a The The album today."