It's not clear from the question, but I assume you are carrying on a profession based in the UK.
Obviously each individual case would need to be looked at based on the facts of that case, but in general, we would look at what quality the payment has in the hands of the recipient.
So if the payment for appearing as a professional witness has come to them by way of their profession then it's likely that this would be classed as a professional trading receipt.
If there were then any expenses incurred in carrying this out then they may be claimed to set off against the income received using the normal wholly and exclusively rules.
If it does not fall to be included as a trading receipt then the miscellaneous income provisions would likely apply, again allowing any expenses incurred wholly and exclusively.
BIM40051 - Receipts: general: whether trading income
This guidance covers receipts of the trade in a general sense.