The Rstudio connection pane reacts to Connection contract that is included in package. In your case, this is the odbc package that has the connection contract. And it is clever enough to know when the dbConnect function is ran from the top level or from inside the function. In the second case, it won't open the connection pane. This is because often when not executed from top level, it is often inside a script and you don't want to have the connection that opens in that case.
The trick is here in source code and is quite complicated.