Jordi,
TSTART, TROLLBACK TCOMMIT is totally unrelated to LOCKing
it neither requests a LOCK nor does it release.

So to have no LOCK at all nothing prevents you from 

TSTART
Do ##class(MyTable).%OpenId(<TableID>, 0)
. . . . .
TROLLBACK 

The short time internal LOCK during %Save() is handled inside Save 

In your example:

TSTART
Lock  +^MyLock
TROLLBACK

you just miss 

Lock  -^MyLock

to unlock your transaction 

Pls. forget "store it as it is" all you store is the oref (a pointer to a local structure) with no persistent storage behind.

set local= dynamicObject.%ToJSON()
set classObj.Test = "my dynamicObject = "_$LENGTH(local)

so you don't get an error if you just apply  %ToJSON()  ???

 If your version is before 2016.2  than .$toJSON() would be the right method

You didn't indicate the line you get the error.
anyhow the message is clear:
Either classObj or dynamicObject is not what you expect it to be.
If you test from Terminal you can use

ZWRITE classObj
ZWRITE dynamicObject

to see what they are.

otherwise, you may comment out one line and see if it still breaks e.g.

// set local= dynamicObject.%ToJSON()
set classObj.Test = "my dynamicObject = "_$ISOBJECT(dynamicObject)

So you see what happens.  I expect:  my dynamicObject = 0

So you see where you have to investigate further

is it defined that way?
Property Test as %String (MAXLEN="") ;

ATTENTION - default MAXLEN = 50 !!!!!

This might look odd but try

set local= dynamicObject.%ToJSON()
set classObj.Test = local

 
so you see if the issue is your property  
or your dynamic Object. as there are 2 objects in the command.
the only thing %String is checked against is Length. 
otherwise. if %ToJSON() fails your dynamic object is broken somehow

You can't just set the dynamic object (exactly the oref) to  %String.
You place than just a reference of a local structure to your message.  That's useless.
you need to 

Set classObj.Test = DynamicObject.%ToJSON()

Now you have your string that gets persisted and is part of your message.

Suggested reading: Converting Dynamic Entities to and from JSON​