With a tip of the hat to @TessellatingHecker, let me agree that one line will suffice, but I believe it is this one line that is needed:
$srcPath -replace [Regex]::Escape($topDir), $destDir
Now let's encapsulate that in a function...
function MapSubDir($srcPath, $topDir, $destDir)
{
$srcPath -replace [Regex]::Escape($topDir), $destDir
}
And feed it your original two test cases to observe you get your desired results:
PS> $srcPath= "C:\path\topdir\"
PS> $topDir= "C:\path\topdir\"
PS> $destDir= "\\server\path\"
PS> MapSubDir $srcPath $topDir $destDir
\\server\path
PS> $srcPath = "C:\path\topdir\subpath\subpath1"
PS> MapSubDir $srcPath $topDir $destDir
\\server\path\subpath\subpath1