Have you tried sending your pet to town in order to sell its inventory? If that doesn't work (because your pet cant move at all) then try sending it to town when your far away from it (check the inventory first so you don't sell things you want to keep). It is a known bug for characters, pets, and monsters to become lodged within a wall because of knock-back in all versions of Torchlight (this is partially due to the physics engine that is coded into the game). It is generally uncommon for it to happen though, and I have not had the problem occur as of yet.
Manual fix (will take a long time and I do not know of the possible consequences):
Close Torchlight
To enable the console go into your Torchlight AppData folder: C:\Users\(Username)\AppData\Roaming\runic games\torchlight
Then Open the "settings.txt" file and changing the number after console from 0 to 1 (it is the second item on the list of settings there)
Open your game
Load your character
You can open the console while in the game by:
American English keyboard: Shift and ~
British English keyboard: Shift and #
Norwegian keyboard: Shift and Ø
German keyboard: Shift and ö
Disable your pet through the console by using the "disablepet" command
Close the console
Create a Town Portal near where your pet is stuck and go through it
If it works your pet should come through the portal with you
Then to enable your pet again type "disablepet"
-♠