BUG: fix #59950 handle duplicate column names in dataframe queries
### Issue Description

When calling `DataFrame.query()` on a DataFrame with duplicate column names, an unexpected `TypeError` is raised due to a change introduced in pandas 2.2.1. The root cause is the `self.dtypes[k]` returning a Series for duplicate column names instead of a single value, leading to a failure in the query evaluation.

### Changes Made

- Fixed an issue where `Dataframe.query()` would throw an unexpected error

- The error was caused by `self.dtypes[k]`

- Adjusted the behavior to match the behavior prior to pandas version

- Added tests to ensure that `Dataframe.query()` works as expected

## PR Checklist

- [x] closes #59950
- [x] [Tests added and passed](https://pandas.pydata.org/pandas-docs/dev/development/contributing_codebase.html#writing-tests) if fixing a bug or adding a new feature
- [x] All [code checks passed](https://pandas.pydata.org/pandas-docs/dev/development/contributing_codebase.html#pre-commit).
- [x] Added [type annotations](https://pandas.pydata.org/pandas-docs/dev/development/contributing_codebase.html#type-hints) to new arguments/methods/functions.
- [x] Added an entry in the latest `doc/source/whatsnew/vX.X.X.rst` file if fixing a bug or adding a new feature.

Thanks @miguelcsx 