Can i connect something else to programming pins in STM32 (SWD)?
Yes, you can use STM32 SWD pins as GPIO, and yes, you need to think about the impact of doing so on the SWD functionality.

Likely you want anything else driven by those lines to be behind a buffer with a high impedance input, and you want anything that could drive those lines to be behind a specific enable.

But there's also a risk in re-purposing those lines, especially as GPIO output.  If you do so, you will not be able to connect an SWD probe to the running system.  

With a full capability SWD adapter, you should be able to perform a coordinated "connect under reset" where the CPU core is reset and the SWD connection is used to suspend operation before the program can re-purpose the pins and disable SWD.  However, this can be difficult with some setups.

So generally, if you are going to re-purpose the pins, it's best for a program to provide a second or two of delay upon reset before doing so.

You probably also want to make doing so at all dependent on a macro definition, perhaps one passed on the compiler command line.  That way, if you decide you want to use a breakpoint debugger, you can build the code with alternate settings that do not re-purpose the SWD pins (maybe something like arm-non-eabi-gcc -DNO_REPURPOSE_SWD), and so leave them operating in SWD mode to permit the debugger to function.

And of course whatever you connect to those pins needs to not problematically mis-operate if it sees SWD traffic rather than the intended signals.  So things like motor drives are a very bad idea; but status LEDs, or serial advisory message outputs might be okay.